DEV Community

loading...
Cover image for Learn Kubernetes, Part I, Basics, Deployment and Minikube
Microsoft Azure

Learn Kubernetes, Part I, Basics, Deployment and Minikube

Chris Noring
https://twitter.com/chris_noring Cloud Developer Advocate at Microsoft, Google Developer Expert
Originally published at softchris.github.io Updated on ・7 min read

Follow me on Twitter, happy to take your suggestions on topics or improvements /Chris

Kubernetes is about orchestrating containerized apps. Docker is great for your first few containers. As soon as you need to run on multiple machines and need to scale/up down and distribute the load and so on, you need an orchestrator - you need Kubernetes

This is the first part of a series of articles on Kubernetes, cause this topic is BIG!.

  • Part I - from the beginning, Part I, Basics, Deployment and Minikube we are here
  • Part II introducing Services and Labeling In this part, we deepen our knowledge of Pods and Nodes. We also introduce Services and labeling using labels to query our artifacts.
  • Part III Scaling Here we cover how to scale our app
  • Part IV - Auto scaling In this part we look at how to set up auto-scaling so we can handle sudden large increases of incoming requests

In this part I hope to cover the following:

  • Why Kubernetes and Orchestration in General
  • Hello world: Minikube basics, talking through Minikube, simple deploy example
  • Cluster and basic commands, Nodes, 
  • Deployments, what it is and deploying an app
  • Pods and Nodes, explain concepts and troubleshooting

 Why Orchestration

Well, it all started with containers. Containers gave us the ability to create repeatable environments so dev, staging, and prod all looked and functioned the same way. We got predictability and they were also light-weight as they drew resources from the host operating system. Such a great breakthrough for Developers and Ops but the Container API is really only good for managing a few containers at a time. Larger systems might consist of 100s or 1000+ containers and needs to be managed as well so we can do things like scheduling, load balancing, distribution and more.

At this point, we need orchestration the ability for a system to handle all these container instances. This is where Kubernetes comes in.

Resources

Kubernetes 

So what do we know about Kubernetes?

It's an open-source system for automating deployment, scaling, and management of containerized applications

Let'start with the name. It's Greek for Helmsman, the person who steers the ship. Which is why the logo looks like this, a steering wheel on a boat:

It's Also called K8s so K ubernete s, 8 characters in the middle are removed. Now you can impress your friends that you know why it's referred to as K8.

Here is some more Jeopardy knowledge on its origin. Kubernetes was born out of systems called Borg and Omega. It was donated to CNCF, Cloud Native Computing Foundation in 2014. It's written in Go/Golang.

If we see past all this trivia knowledge, it was built by Google as a response to their own experience handling a ton of containers. It's also Open Source and battle-tested to handle really large systems, like planet-scale large systems.

So the sales pitch is:

Run billions of containers a week, Kubernetes can scale without increasing your ops team

Sounds amazing right, billions of containers cause we are all Google size. No? :) Well even if you have something like 10-100 containers, it's for you.

 Getting started

Ok ok, let's say I buy into all of this, how do I get started?

Impatient ey, sure let's start to do something practical with Minikube

Ok, sounds good I'm a coder, I like practical stuff. What is Minikube?

Minikube is a tool that lets us run Kubernetes locally

Oh, sweet, millions of containers on my little machine?

Well, no, let's start with a few and learn Kubernetes basics while at it.

Installation

To install Minikube lets go to this installation page

It's just a few short steps that means we install

  • a Hypervisor
  • Kubectl (Kube control tool)
  • Minikube

 Run

Get that thing up and running by typing:

minikube start
Enter fullscreen mode Exit fullscreen mode

It should look something like this:

You can also ensure that kubectl have been correctly installed and running:

kubectl version
Enter fullscreen mode Exit fullscreen mode

Should give you something like this in response:

Ok, now we are ready to learn Kubernetes.

 Learning kubectl and basic concepts

In learning Kubernetes lets do so by learning more about kubectl a command line program that lets us interact with our Cluster and lets us deploy and manage applications on said Cluster.

The word Cluster just means a group of similar things but in the context of Kubernetes, it means a Master and multiple worker machines called Nodes. Nodes were historically called Minions

, but not so anymore.

The master decides what will run on the Nodes, which includes things like scheduled workloads or containerized apps. Which brings us to our next command:

kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

This should give us a result like this:

What this tells us what Nodes we have available to do work.

Next up let's try to run our first app on Kubernetes with the run command like so:

kubectl run kubernetes-first-app --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080
Enter fullscreen mode Exit fullscreen mode

This should give us a response like so:

Next up lets check that everything is up and running with the command:

kubectl get deployments
Enter fullscreen mode Exit fullscreen mode

This shows the following in the terminal:

In putting our app on the Kluster, by invoking the run command, Kubernetes performed a few things behind the scenes, it:

  • searched for a suitable node where an instance of the application could be run, there was only one node so it got chosen
  • scheduled the application to run on that Node
  • configured the cluster to reschedule the instance on a new Node when needed

Next up we are going to introduce the concept Pod, so what is a Pod?

A Pod is the smallest deployable unit and consists of one or many containers, for example, Docker containers. That's all we are going to say about Pods at the moment but if you really really want to know more have a read here

The reason for mentioning Pods at this point is that our container and app is placed inside of a Pod. Furthermore, Pods runs in a private isolated network that, although visible from other Pods and services, it cannot be accessed outside the network. Which means we can't reach our app with say a curl command.

We can change that though. There is more than one way to expose our application to the outside world for now however we will use a proxy.

Now open up a 2nd terminal window and type:

kubectl proxy
Enter fullscreen mode Exit fullscreen mode

This will expose the kubectl as an API that we can query with HTTP request. The result should look like:

Instead of typing kubectl version we can now type curl http://localhost:8001/version and get the same results:

The API Server inside of Kubernetes have created an endpoint for each pod by its pod name. So the next step is to find out the pod name:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

This will list all the pods you have, it should just be one pod at this point and look something like this:

Then you can just save that down to a variable like so:

Lastly, we can now do an HTTP call to learn more about our pod:

curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME
Enter fullscreen mode Exit fullscreen mode

This will give us a long JSON response back (I trimmed it a bit but it goes on and on...)

Maybe that's not super interesting for us as app developers. We want to know how our app is doing. Best way to know that is looking at the logs. Let's do that with this command:

kubectl logs $POD_NAME
Enter fullscreen mode Exit fullscreen mode

As you can see below we know get logs from our app:

Now that we know the Pods name we can do all sorts of things like checking its environment variables or even step inside the container and look at the content.

kubectl exec $POD_NAME env
Enter fullscreen mode Exit fullscreen mode

This yields the following result:

Now lets step inside the container:

kubectl exec -ti $POD_NAME bash
Enter fullscreen mode Exit fullscreen mode

We are inside! This means we can see what the source code looks like even:

cat server.js
Enter fullscreen mode Exit fullscreen mode

Inside of our container, we can now reach the running app by typing:

curl http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

Summary

This is where we will stop for now.
What did we actually learn?

  • Kubernetes, its origin what it is
  • Orchestration why you will soon need it
  • Concepts like Master, Nodes and Pods
  • Minikube, kubectl and how to deploy an image onto our Cluster

Feel like you have a ton more to learn? You're right this is a big topic.

I hope you follow along on the next upcoming parts where we will learn more about Nodes, Pods, Services, Scaling, Updating and eventually how to use a managed service in the Cloud.

Click here for the Next part

Discussion (40)

Collapse
thorstenhirsch profile image
Thorsten Hirsch

It's Also called K8s so Kubernete*s*, 8 characters in the middle are removed. Now you can impress your friends that you know why it's referred to as K8.

I always thought the reason for this is that "ete" in "Kubernetes" sounds like an 8, so we have "Kubern8s". What kind of eights? Well, "Kubern" eights are not a real thing, so we skip the "ubern", and now we have "K'8s", which just becomes "K8s".

Collapse
softchris profile image
Chris Noring Author

Hi Thorsten. This is what Google themselves say..

kubernetes.io/docs/concepts/overvi...

But who knows what else is true ;)

Collapse
sambenskin profile image
Sam Benskin

Yeah it's a similar principle to internationalisation being shortened to i11n as it has 11 letters in the middle and just makes it quicker to type and slightly quicker to say

Thread Thread
thorstenhirsch profile image
Thorsten Hirsch

But... it's i18n, because 18 letters have been dropped.

Thread Thread
sambenskin profile image
Sam Benskin

...doh!

Collapse
jayendran profile image
Jayendran Arumugam

After running the below

kubectl run kubernetes-first-app --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080

When I run kubectl get deployments its gives back like No resources found in default namespace.

So I ran like
kubectl create deployment kubernetes-first-app --image=gcr.io/google-samples/kubernetes-bootcamp:v1 --port=8080

Then the deployment list can able to work. Not sure whether I missed any earlier steps.

Collapse
shaijut profile image
Shaiju T

Hi Chris,

I have a doubt whether Its worth for .NET developers to learn kubernetes. Can you explain by adding some comment on below post. I have posted it long ago but no answers.

dev.to/shaijut/kubernetes-vs-azure...

Collapse
softchris profile image
Chris Noring Author

hi Shaijut. In trying to answer you I must make some assumptions. When you say .NET you mean .NET and not .NET Core.. Let's assume you are doing .NET Core, so you can easily containerize. Otherwise I think App Service is your only option. For me, Kubernetes vs App Service is a matter of what architecture I have. If I have several Microservices rather than a Monolith then I need an orchestrator like Docker Swarm, Kubernetes or similar. The reason is to be able to scale easily, load balance and whatever else you need. App Service does a decent job of scaling as it is a PaaS but I would say if you have a very large operation 500k users and a Microservice Architecture it makes sense to look further into Kubernetes and AKS for example . Azure Service Fabric is another option we have. For ppl already using it, keep using it. For others, look into AKS.. We support multiple ecosystems for containers but all indications I have says the future is Kubernetes. Don't take that as an official statement though

Collapse
shaijut profile image
Shaiju T • Edited

Thanks for detail explanation 😄, Actually I heard someone saying two points 1. For .NET Core Apps Azure Service Fabric is good choice. 2. Use Kubernetes for other stacks like Java, NodeJS etc...

So from your comments I am able conclude that I being a .NET Developer its worth to learn Kubernetes. Actually planning to do Kubernetes certification.

Thread Thread
softchris profile image
Chris Noring Author

np :). Here's some resources to get you started docs.microsoft.com/en-us/azure/aks... dotnet.microsoft.com/apps/aspnet/m...

Collapse
ehanlon profile image
Eammon Hanlon • Edited

Excellent post @softchris !

There are a couple of typos:

  • curl http://localhost:8001/api/v1/namespaces/default/pod/$POD_NAME should be curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME

  • curl http:localhost:8080 should be curl http://localhost:8080

Collapse
softchris profile image
Chris Noring Author

Thanks :) Appreciate your comments

Collapse
dendihandian profile image
Dendi Handian

It's failed to start on my machine:

C:\Users\dendi>minikube start
* minikube v1.15.1 on Microsoft Windows 10 Home Single Language 10.0.19041 Build 19041
* Using the hyperv driver based on existing profile
* minikube 1.16.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.16.0
* To disable this notice, run: 'minikube config set WantUpdateNotification false'

* Starting control plane node minikube in cluster minikube
* Creating hyperv VM (CPUs=2, Memory=3000MB, Disk=20000MB) ...
! StartHost failed, but will try again: creating host: create: precreate: Hyper-V PowerShell Module is not available
* Creating hyperv VM (CPUs=2, Memory=3000MB, Disk=20000MB) ...
* Failed to start hyperv VM. Running "minikube delete" may fix it: creating host: create: precreate: Hyper-V PowerShell Module is not available

X Exiting due to PR_HYPERV_MODULE_NOT_INSTALLED: Failed to start host: creating host: create: precreate: Hyper-V PowerShell Module is not available
* Suggestion: Run: 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Tools-All'
* Documentation: https://www.altaro.com/hyper-v/install-hyper-v-powershell-module/
* Related issue: https://github.com/kubernetes/minikube/issues/9040
Enter fullscreen mode Exit fullscreen mode
Collapse
softchris profile image
Chris Noring Author

Seems like the error message is saying what's wrong

Hyper-V PowerShell Module is not installed
Enter fullscreen mode Exit fullscreen mode

Here's a thread where people seem to have a similar issue, maybe that helps?
github.com/kubernetes/minikube/iss...

Collapse
acho_arnold profile image
αςнο αяηοℓδ

Thanks for this awesome writeup. I think there's a little typo here

Instead of typing kubectl proxy we can now type curl http://localhost:8001/version and get the same results:

I think it should be

Instead of typing kubectl version we can now type curl http://localhost:8001/version and get the same results:

Collapse
softchris profile image
Chris Noring Author

Hi thanks. Appreciate you pointing that out :)

Collapse
sambenskin profile image
Sam Benskin

Great read, thanks for sharing your knowledge in an easy to understand way. Looking forward to part 3.

Just a small suggestion. A link to the next article in the series at the bottom helps the reader move on without having to scroll all the way back to the top to find the link

Collapse
softchris profile image
Chris Noring Author

Hi Sam. Thanks for that. Will update it

Collapse
sambenskin profile image
Sam Benskin

You're welcome 😀

Collapse
mgh87 profile image
Martin Huter

Really nice post.

I got a small setup at home for some local services with docker-compose. Do you think its worth it to switch to k8s with a single node (master)? Or is it to much overhead to maintain it?

Collapse
softchris profile image
Chris Noring Author

hi Martin.. I'd say it depends. If you are hosting it in the Cloud then horizontal scaling is enabled by default and that might be all you need. To me it sounds like it might be overkill but trying it out on a hobby basis is how most of us learn anything

Collapse
jericomanapsal profile image
jericomanapsal

Great, soft, and effective introduction about k8s. I'm looking forward for part two. In fact, I'm looking forward to the entire series. Please do more ☸️

Collapse
softchris profile image
Chris Noring Author

part two is here dev.to/azure/kubernetes-part-ii-re... working on part 3 :)

Collapse
wizardrogue profile image
Joseph Angelo Barrozo

Dang it. Take my heart. I appreciate that high quality gif.

Collapse
maurycyszmurlo profile image
Maurycy Szmurlo

Nice read, Chris. Looking for next part!

Collapse
henrik_oliveira profile image
Henrique Oliveira

when will you do part 2. I am exciting about it.

Collapse
softchris profile image
Chris Noring Author
Collapse
gwllmnn profile image
Grégoire Willmann

Excellent introduction! Thank you!

Collapse
softchris profile image
Chris Noring Author

Thank you :)

Collapse
theodesp profile image
Theofanis Despoudis

Awesome

Collapse
goranpaunovic profile image
Goran Paunović

For windows 10 users with HyperV, you must explicitly specify 'hyperv' as a driver since minikube use VirtualBox by default.

minikube start --vm-driver=hyperv

Collapse
realabbas profile image
Ali Abbas

Exceptional Post on Dev.to about Kubernetes a.k.a K8. Already looking forward to Part II

Collapse
softchris profile image
Chris Noring Author

hi Ali. Really appreciate that comment.. thank you.. Yes will work hard to release second part in the next few days :)

Collapse
samplezt profile image
Lucas Griotti

Thanks a lot. I learn so much of all your articles

Collapse
softchris profile image
Chris Noring Author

hi Lucas. That's very nice of you to say. Thank you.. :)

Collapse
sathyasarathi90 profile image
Sathyasarathi

Nodes were historically called Minions, but not so anymore. :(

Collapse
softchris profile image
Chris Noring Author

yea it's the most disappointing thing about K8s :)

Collapse
ariaseta profile image
Ariaseta Setia Alam

Wow awesome, can't wait for part 2

Collapse
softchris profile image
Chris Noring Author

hi Ariaseta. Thanks for the comment :). The 2nd part is gonna be published in the next week.