Kubernetes: Getting Started (from your laptop)

0
Share

Reading time: 15 minutes

In this tutorial I will walk you through the steps of getting started with Kubernetes for the first time – using a laptop instead of a cloud platform (AWS, Azure, GoogleCloud, etc). Let’s save some money during your learning and development! This is a great way to become familiar with creating Kubernetes deployments and learn something new. In the past, I showed you how to deploy Kubernetes from the Microsoft Azure cloud- Link. You’ll notice that the computer setup is a bit more involved than simply using the Azure CLI, but the reward is that you won’t need an Azure tenant (As I mentioned, hopefully it will save you some money and allow you to use what you already have available). Now we’ll take a step back and I’ll show you how to deploy Kubernetes from your laptop. As my friend Gustavo, a cloud architect, would say “Let’s come back down from heaven (the cloud-AWS/Azure, etc) to earth (on-premise/local environment)”!

For this tutorial, we’ll setup Kubernetes to run locally on your system and then run a helloworld website from a docker image pulled from my Dockerhub repo (ksapp/docker-hello-world).

The Background Details:

What is containerization?

Containerization is a lightweight alternative to full machine virtualization that involves encapsulating an application in a container with its own isolated operating environment (using extracted OS kernel components). (3)

What is Kubernetes?

Kubernetes (k8s) is an open-source system, created by Google, for automating deployment, scaling, and management of containerized applications. It is portable and extensible for managing containerized workloads and services, and it facilitates DevOps goals for declarative configuration and automation. Kubernetes has a large, rapidly growing ecosystem and is starting to become an industry standard. 

Why should I learn Kubernetes?

For career growth so that you can keep up with the trends. The IT industry is slowly moving away from company teams that only focus on Operational level projects (Systems Administrators\ System Engineers building and maintaining monolithic systems that are coupled together and load balanced) to microservices (Basically DevOps\SRE Engineers who breakdown system components into small silos so that the company infrastructure is deployed in a way that is robust and codified). This handles horizontal scaling issues that most companies face (saving money and handling application upgrades, source control/auditing, high vs low peak system performance, and standardizing the company infrastructure).

What is Minikube?

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a VM on your laptop for people looking to try out Kubernetes or develop with it day-to-day (1).

What is a Pod?

Disposable docker containers used to run jobs. If a pod breaks then it’s not a big deal- since it can easily be recreated and deployed automatically (self healing system).

pod

Source: (2)

What is inside a Pod?

  • The Docker application used to create the containers
  • Storage resources
  • Unique network IP
  • Built-in components from the Docker image

What is inside a ReplicaSet?

The purpose of a Kubernetes ReplicaSet is to maintain the state of a set of Pods running at any given time. A ReplicaSet fulfills the purpose of creating and deleting Pods as needed to reach a desired number of availability- using pod metadata to specify which object owns the ReplicaSet (via the metadata.ownerReferences field). Most of the time ReplicaSets do not need to be changed or managed directly (it’s better practice to use a Kubernetes deployment – see below).

What is inside a deployment?

The deployment is where a lot of the Kubernetes “magic happens”. Kubernete deployments use a Deployment controller to provide declarative updates for Pods and ReplicaSets – scale up Pods, rollback configurations, create\delete ReplicaSets, etc. Thedeployment carries out the desired state configuration using a Deployment object, and the Deployment controller changes the current state to the desired state at a controlled rate. When you start deploying Pods using a ReplicaSet, and then try deleting pods individually. You’ll notice that these pods will automatically get recreated – well the process behind that is the deployments desired state for the ReplicaSet.

How scalable is Kubernetes?

Scalability (v 1.8)

  • Supports 5,000 node clusters
  • 150,000 total pods
  • Pods can be horizontally scaled via API

What are the Kubernetes components?

Kubelet – “Kubernetes node agent” that runs on each node. It communicates with the API server to gather pod / node status information. It runs using a YAML file (Podspec) – which describes the pod.

Kube-proxy – Process that runs on all of the worker nodes. This handles the network steams and forwarding of traffic in the backend.

Kubectl – a command line interface for running commands against Kubernetes clusters. 

What does the Kubernetes architecture look like?

Source: (2)

Setup the Prerequisites

Let’s make sure that you have everything that we’ll need to get started.

  • Hypervisor (Virtualbox\Hyper-V)
  • Docker engine
  • KubeCtl (Kubernetes CLI)
  • MiniKube

Download and Install Virtualbox or Enable Hyper-V on your Windows 10 machine

https://www.virtualbox.org/wiki/Downloads

Install Docker on your machine

https://www.docker.com/get-started

Verify that Docker is installed and started

Open a terminal window/command line and type:

docker version

I’m running version 18.09.2 at this time. You’ll need at least version 17.0+

Install Kubectl on your machine

https://kubernetes.io/docs/tasks/tools/install-kubectl/

For my Mac laptop, I used the following commands to install Kubectl using Brew:

brew install kubernetes-cli

Then verify that kubectl is installed. You will see an error for connecting to the server – since we haven’t set that up yet:

kubectl version

Install Minikube

https://kubernetes.io/docs/tasks/tools/install-minikube/

Ready, set, go!

Let’s run our first Hello World application.

Start Minikube (Make sure that Hyper-V or Virtualbox is running on your machine)

minikube start

Verify that Minikube and Virtualbox are connected:

kubectl get nodes

Output:

Now that Minkube is running. Let’s launch the hello world website.

Run the following commands:

kubectl run hello-minikube --image=ksapp/docker-hello-world:latest --port=8080    

Output: deployment.apps “hello-minikube” created

kubectl expose deployment hello-minikube --type=NodePort

Output: service “hello-minikube” exposed

Now we can check to see if the pod is running:

kubectl get pod

Output:

Open the Helloworld website in a browser

minikube service hello-minikube

This will automatically open a browser and connect to the MiniKube helloworld web application:

**Every time that you reload the page, the visit counter will increment by 1

We can see the TCP port mapping details by running the following kubectl command:

kubectl get services

Output:

NAME      TYPE    CLUSTER-IP   EXTERNAL-IP PORT(S)    AGE

hello-minikube NodePort  10.97.203.1   <none>    80:30108/TCP 5m

As you can see port 80 is mapped to port 30108 on my machine.

Finally, let’s cleanup our helloworld Kubernetes deployment

Delete the deployment and pods

kubectl delete deployment hello-minikube

Delete the listening service

kubectl delete svc -l run=hello-minikube

There we have it. We have deployed a simple helloworld application using Kubernetes via Minikube.

Learn More (Helpful Links)

Microsoft Azure: How to deploy an Azure Kubernetes Service (AKS) cluster via the Azure CLI by Kevin Sapp (LinkedIn Engineer)

KuberCon – http://events.linixfoundation.org

Meetups – https://www.meetup.com/topics/kubernetes

Slack Channel – https://kubernetes.slack.com

Learn Kubernetes the Hard way by Kelsey Hightower (Google Engineer) – https://github.com/kelseyhightower/kubernetes-the-hard-way

Kubernetes Documentation: https://kubernetes.io/docs/home

References:

(1) https://kubernetes.io/docs/setup/pick-right-solution/

(2) Linkedin Learning Course : Learning Kubernetes by Karthik Gaekwad 

(3) https://www.webopedia.com/TERM/C/containerization.html

(4) LinkedIn Article : https://www.linkedin.com/pulse/kubernetes-getting-started-from-your-laptop-kevin-sapp

Related Posts