We have launched a free Basic Kubernetes Course. Click here to enrol now! Kubernetes is a container orchestration platform used by enterprises worldwide and Kubernetes developers are in high demand!
In this video we will deploy a docker image containing a static website to Kubernetes. This will be a very short demo just to give you a feel of how Kubernetes looks. In a later section we will go through the process of creating the docker image but for now just enjoy the show.
This course has been developed on a windows laptop but I have installed the linux tools for windows since it gives a nice bash terminal to work with. However, if you chose to use Powershell that should work as well.
Since a production Kubernetes deployment needs multiple nodes, we will use minikube to install a single node cluster on the laptop. Minikube gives us as a basic Kuberentes install to experiment and develop on the laptop or home computer. Also, we will use the docker runtime installed as part of minikube so that we don’t have to install another docker runtime for creating images.
Let me switch to the terminal.
We first start Minikube by typing in minikube.exe start
Lets see the status by typing in minikube.exe status, this says minikube has started successfully.
We have already created an image that contains the static website. Lets check if the docker image is present. kubernetes_static_website is the name of our docker image. Note that we have created the docker image using the minikube container runtime and so its available to kubernetes. In a production environment, the image will be downloaded by the Kubernetes container runtime from a public or private docker repository.
Here’s the index.html page from the website. Its the hello world of Kuberenetes.
The deployment information is written in a yaml file. Lets take a peek into the file without understanding what the lines mean. It has all the information required to deploy the container to kubernetes, information about the number of instances required and information to make it accessible from outside the cluster.
we use the kubectl tool to deploy it. kubectl is a kubernetes command line client. We first see currently deployed applications by typing in
kubectl get deployments.and currently deployed pods by typing in
kubectl get pods.pods host the docker containers. next step is to deploy the static website by using the yaml file that gives the deployment information.
kubectl apply -f static_website_deployment.yml
if we now check the deployments again, we should see our deployment and also our pods. The pods may take a while to start since they
are starting the webserver. There are two instances of the pods which means we have two webservers running. Kubernetes sends traffic to either of the pods and the user does not have to worry about it. The service makes the website accessible from outside the cluster.
for minikube we get the url using minikube.exe service static-website-service –url
if we curl this url we should get the index.html page which says Hello Kubernetes.
We have successfully deployed our first containerized application to kuberentes. Lets look at the minikube dashboard
to see the dashboard we type in minikube.exe dashboard.
This opens up a dashboard in a browser.
On the left side of the dashboard are the various Kubernetes entities or object links.
clicking on deployment brings up the deployments. we only have one deployment. Clicking on pods brings up the pod list, where we currently see 2. Lets see how easy it is to scale applications. Imagine that the traffic on our website has increased and we need one more pod to handle that traffic. We go back to deployments, click on the 3 vertical dots on the right to bring up a menu and click on scale . we change the desired number of pods to 3 and hit ok. we then go back to the pods page and now we should see 3 pods once the third pod has started.
Lets simulate a failed pod by deleting one of the pods. Kuberenetes immediatly brings up another pod since we always want 3 pods for this application.
This finishes our introductory deployment. We have barely scratched the surface but we have already seen an example of how powerful and exciting Kuberenetes can be. It is going to completely revolutionize the way companies handle containers. We will get into great details into all aspects of Kuberenets in the next videos and by the end of the course you should feel pretty confident to handle Kubernetes deployment or if you are brave enough you should have enough knowledge to setup your own production grade cluster.
Stay tuned for the next lecture on Containers!