In the first few lessons of this class, we focused mainly on how to build containers. You saw how they can be useful and how they fit in your development workflow. Now that you took your application and containerized all of the different components, you will want to deploy all of these containers on a server. This is where Kubernetes will come into play.
Kubernetes is an orchestrator platform. It will take care of deploying your containers and making sure that they are always running. If one of these containers should crash, Kubernetes will immediately restart it. It will also take care of the networking between the various containers that you have running in your system.
To define the various objects that compose a Kubernetes cluster, you will need to create YAML files. Those can then be applied to your cluster. This makes it easy to have all the definitions of your cluster inside a git repository.
In the next few lessons, you will take the application you just containerized and will deploy everything into a Kubernetes cluster. Interacting with your Kubernetes instance will be done with a CLI tool called kubectl. This versatile tool can connect to any Kubernetes cluster and let you interact with it from the comfort of your terminal. You will also see how to use various other tools to make it easier for you to manage this cluster.
But before you can configure kubectl, you will need a Kubernetes cluster that you can interact with. There are many options available to you.
Most major cloud providers offer a variant of Kubernetes. While each implementation tends to be slightly different, the examples provided in the next lessons should be working on each one of these using the kubectl tool.
Minikube is a tool to run a tiny Kubernetes instance on your laptop. You would typically run minikube if you wanted to test out your setup in a local environment. It is lightweight and is easy to use. Once you’ve installed minikube, you can use the command start to start a local Kubernetes cluster and automatically configure kubectl to use this cluster.
minikube start
You will need to enable the ingress add-on for one of the future steps so you might as well do it right now with the addons command.
minikube addons enable ingress
If you want to stop it from running, you can use the stop command.
minikube stop
Once minikube is started, it will be automatically be configured with kubectl and you will be ready to get started.
If you eventually want to use an Enterprise-grade Kubernetes cluster, you might want to look into OpenShift. OpenShift is Red Hat’s distribution of Kubernetes. It provides you with all the functionalities that come built-in with Kubernetes as well as a lot of useful tools out of the box, like a very handy UI.
If you want to try out OpenShift locally, you can use Code Ready Containers which is the equivalent of minikube for OpenShift. Once CRC is installed, you can start it with the start command.
crc start
This will take care of starting your local cluster. You will also have the instructions to connect to your cluster and the URL to see the dashboard. It will also take care of configuring kubectl for you. when you are ready to stop the cluster, you can run
crc stop
Once CRC is started, you are ready to go and kubectl will be available to you.
Once you have a running cluster, make sure that your kubectl is connected to the right Kubernetes cluster. You can see the context that kubectl is currently using with the config command.
kubectl config current-context
Once kubectl is connected and properly configured, you are ready to deploy your first object to Kubernetes. This will be done in the next lesson.