Feel free to clone this Gist to follow along!
We will be running a local Kubernetes cluster. If you have an existing Kubernetes cluster you are fond of, feel free to use that instead!
First order of business is to install Minikube.
First, install Docker Desktop for Mac.
Then install minikube using Homebrew.
$ brew install minikube
Next start your local cluster using the hyperkit
hypervisor.
$ minikube start --vm-driver=hyperkit
Follow the Installing Minikube on Linux doc to get minikube setup.
Linux has a few hypervisor options, but I prefer KVM. Download the Minikube kvm2 driver after installing Minikube, then run:
$ minikube start --vm-driver=kvm2
If the minikube start
commands fail, check out the Minikube Drivers docs for other hypervisor options.
You may also need to install kubectl.
The following command should succeed if you have a working cluster:
$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 32m
Now that you have cluster you can start playing around with it!
First we will deploy some Pods to the cluster.
A Pod is a collection of one or more containers.
A Container is a semi-isolated process running on a shared host.
$ kubectl create -f pods.yaml
This will create a pod hosting a small website.
To access the website you just started running, run the following:
$ kubectl port-forward tinsy-app-pod 8001:8000
In your browser go to https://localhost:8001
This port-forwards an application running in a pod onto your local machine.
Now tear down that pod! We have bigger and better things to deploy.
$ kubectl delete -f pods.yaml
Next we will create a deployment.
A Deployment is a declaratively managed ReplicaSet.
A ReplicaSet is a scalable set of replicated Pods; common for creating Highly Available apps.
$ kubectl create -f deployment.yaml
This deploys three instances of our application (Pods) whose life-cycles are managed by a Kubernetes ReplicaSet.
To access these three instances as one application we need to create a Kubernetes Service
.
A Service is a load-balanced interface to an application.
$ kubectl create -f service.yaml
This exposes our application over a randomly assigned port to our local system.
Find the IP address of our Kubernetes node, and go to : in your browser. Find the port with kubectl get -f service.yaml
.
Note: Reload the application a few times, notice the HOSTNAME variable change value.