Blog Post 1 and what to expect.
In our last post we went over an introduction to both Docker and Kubernetes. We have introduced the containerization of applications using Docker and how that revolutionized how applications are deployed and maintained in high scalable systems. We have also introduced an orchestrator which is kubernetes, we have learned the basic architecture as well as the main purpose of using such platform. If you would like to read the full blog post, I invite you to do so here .
Moving on to today’s blog post in which we will explore how everything works by doing a hands on mini project that consists of deploying a local kubernetes as we do not have an infrastructure with several servers on hand. We will first explore some tools that we will need such as Minikube, kubectl and some other tools as well. At the end of this mini project we will have a better grasp on how everything works. After having a full local cluster that is up and running we will deploy wordpress and mysql.
Moving on to today’s blog post in which we will explore how everything works by doing a hands on mini project that consists of deploying a local kubernetes as we do not have an infrastructure with several servers on hand. We will first explore some tools that we will need such as Minikube, kubectl and some other tools as well. At the end of this mini project we will have a better grasp on how everything works. After having a full local cluster that is up and running we will deploy wordpress and mysql.
Minikube ☸️
When working with kubernetes we usually aim to scale our applications and services across multiple servers whatever we are deploying them on an AWS EC2 cloud instance or if we are working with a hybrid architecture. This is where Minkube comes into the picture, minikube is meant to be used locally in order for us to play around with kubernetes and use it as a safe space to test our environment before deploying it to production. Instead of having multiple masters and workers nodes minikube englobes everything under one node cluster that already have docker pre-installed. Minikube will be hosted on a virtual machine. In a nutshell, minikube will create a virtual machine for us and run the node on that virtual machine. In this short video we will showcase how we can get minikube up and running on our machine. Please note that we already assume that you have a hypervisor already installed on your machine i.e: Virtual Machine, VMware, etc.
Minikube Dashboard
Remember writing your first java program on a Notepad++, it was not the best experience. Let say you have not declared a variable correctly or forgot to import a library Notepad++ won’t give you any alerts but Eclipse does. I think beginners to kubernetes should be introduced to the dashboard in order for them to feel more comfortable playing around with things such as deploying applications, getting information about the running applications and their usage, but most importantly to be able to debug your cluster. Kubernetes is a really broad environment and it will take you some time to mastering it. Having a dashboard will give you a some reassurance and a peace of mind so feel free to explore the several section of the dashboard and work your way to becoming a kubectl master 🤓
Exploring Basic Kubectl Commands
Before jumping to the next part which is deploying our Wordpress instance with Kubernetes let’s explore some of the useful kubectl commands. Before creating a deployment of our Wordpress I will create a hello world deployment in order to showcase some of the commands. I will explain each part and you can also watch the recording of my shell to see the output that I am getting.
In order to create a deployment we can use the command line or use a deployment file which we will look into that in the next section of this blog post.
In order to create a deployment we can use the command line or use a deployment file which we will look into that in the next section of this blog post.
kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4
: As you can see in the deployment above we are using the kubectl create deployment command that takes the name that we would like to git to our node followed by the image name. In this case we are providing the kubernetes hello world image
kubectl config view
: gives us a verbose output of our current configuration
kubectl get services
: lists all our services
kubectl get pods
: lists all the pods that we currently have
kubectl get events
: list the events that are happening in our cluster
kubectl logs pod-name
: Gives us the logs of the specified pod
Deployments
As we saw in the previous section deploying a pod can be easily done with one line of code. We simply explored the tip of the iceberg as in a real cluster we will need to add more than the node name and the image name. We might need to add how many replicas we need, the ports that we would like to expose for our services and more other options that we can apply. Using the terminal for such thing is not efficient as we can lose track of things and we will also get overwhelmed. That is where the deployment file comes handy to help us have a readable file that can be shared across our organization and can also be reused in other clusters. We have here an example of a deployment file for an nginx server with three replicas all exporting port 80.
Now that we have a deployment file all we need to do is to make sure we are on the same directory and simply run ```kubectl apply -f name-of-deployment-file.yaml```. If we need to update anything regarding our deployment we simply edit the file and run the same command again and kubectl will take care of updating the deployment for us.
Deploying WordPress and MySQL
We are now ready to deploy our wordpress instance to our cluster, we also need a database and we will be using mysql. Before doing anything we need to make sure that we need to generate a secret file in order to save our database credentials. As you can see I am using a plain text password but I strongly advise you not to do the same thing on a production system. It is best to encode or hash your password with a base64 for example.
Once we have our deployment files ready all we need to do is deploy everything and wait for it for kubectl to do its magic 🎩🧙♂️ in the back end. We can also use the dashboard to visualize everything and get an actual status of what is going on as the terminal does not give us a progress bar. (Something kubectl might want to add in the future? 😉🧐)
Once we have our deployment files ready all we need to do is deploy everything and wait for it for kubectl to do its magic 🎩🧙♂️ in the back end. We can also use the dashboard to visualize everything and get an actual status of what is going on as the terminal does not give us a progress bar. (Something kubectl might want to add in the future? 😉🧐)
Conclusion
In this post we have had the chance to get our hands dirty with a mini project that gave us enough confidence on how to use kubernetes. We have learned the usage of kubectl as well as how minikube replicates a cluster environment locally. We also had the chance to learn the basic kubectl commands that can help us deploy a minimal environment. Speaking of environment we have learned the importance of yaml files and how useful they are in the deployment of our services. Finally we were able to have a Wordpress instance up and running and we did track the progress of our deployment from the dashboard like real pros! The journey is still long and we have simply touched the tip of the iceberg🥶🧊. After all kubernetes is not easy even Google themselves admitted it, but that should not stop us from diving deeper in their documentation and learn as much as we can.
I invite you to read this recent article posted on hacker news
References
- Kubernetes Documentation
- Docker Hub
- Docker Documentation
- minikube Documentation
- Overview of kubectl
- VMware Fusion
- MySQL Documentation
- WordPress Documentation
Word Count ≈ 1200
Emoji Count: 8