Earlier we had an article about installing Kubernetes on CentOS and Ubuntu, and this time we go for CoreOS. CoreOS container Linux is an OS that uses containers for all applications you install to it, and does not have package manager like RPM or APT. Together with Ubuntu and CentOS it is one of popular platforms for deploying Kubernetes. We are going to set up Kubernetes on CoreOS with Vagrant.
We need Virtual Box, Vagrant and Git as dependencies. So lets install them. I have fedora on my workstation so the command would be as follows:
sudo dnf install VirtualBox vagrant git
For VirtualBox you would need to have the RMPfusion enabled. If you are using Ubuntu, you would type the following command
sudo apt install virtualbox vagrant git
Rest of this guide is distribution independent.
How to Install kubectl
On our local machine, we need to also install kubectl, to manage our cluster that will be created as set of VMs in Virtual Box. Use this command to get kubectl 1.5.2 which is newest version at the time of writing of this article.
curl -O https://storage.googleapis.com/kubernetes-release/release/v1.5.2/bin/linux/amd64/kubectl
Next we need to add executable bit for the kubectl binary we just downloaded
chmod +x kubectl
And then move it into some directory which is in the path
sudo mv kubectl /usr/local/bin/kubectl
Bringing up the cluster
Next lets clone the repository which has a Vagrantfile we need to start our cluster
git clone https://github.com/coreos/coreos-kubernetes.git
Next move to sub directory that contains Vagrantfile
There we will need to use template (which is config.rb.sample) to create config.rb file that is read by vagrant when we bring up the cluster.
cp config.rb.sample config.rb
Now when we did that, lets edit it.
In the file, we need to uncomment some lines
If you need more resources for your application, feel free to uncomment all the lines and increase the sizes of RAM assigned. Be sure that your workstation has enough RAM, though.
After that, we are ready to bring up the cluster.
vagrant up --provider=virtualbox
This can take some time depending on the speed of your interment connection and I/O. When it is done, we will need to set the context of kubectl to manage our cluster in the VMs
kubectl config use-context vagrant-multi
After this is done, you can look for nodes with following command
kubectl get nodes
Note that on first attempt this command might not work. Instead, you might get an error saying that connection is refused and asking if you specified correct port number. That is because it takes time for Vagrant to boot and connect the cluster. Just wait several minutes and try again.
Deploying the application
Deploying applications to this newly created cluster is straightforward. We will use same sock shop application like we did for CentOS and Ubuntu.
kubectl create namespace sock-shop
Command above created a sock-shop namespace, and following command will get application installed:
kubectl apply -n sock-shop -f "https://github.com/microservices-demo/microservices-demo/blob/master/deploy/kubernetes/complete-demo.yaml?raw=true"
Now we check pods
[miki@latitude-e5470 vagrant]$ kubectl get pods
No resources found.
What is this? No pods? Well off course there is no pods when we put them all into namespace called sock-shop. So this command will get you pods
kubectl get pods -n sock-shop
There is a lot of them and you might need to wait some time for them all to deploy.
Accessing the application in your browser
Application can be accessed from your workstation using any browser. For that, we need to know IP address of our master node and port that application uses. First we get with already known command
[miki@latitude-e5470 vagrant]$ kubectl get nodes
NAME STATUS AGE
172.17.4.101 Ready,SchedulingDisabled 3h
172.17.4.201 Ready 3h
172.17.4.202 Ready 3h
172.17.4.203 Ready 3h
First one is master, so address I am looking for is 172.17.4.101. To this address we also need to add port of front-end container.
[miki@latitude-e5470 vagrant]$ kubectl describe svc front-end -n sock-shop
Port: <unset> 80/TCP
NodePort: <unset> 30001/TCP
Session Affinity: None
It is port 30001 in my case. So the address we are looking for is http://172.17.4.101:30001
How to Remove App from cluster
If you want to remove the application from the cluster, for example to make space for new application, that is also done pretty easily. You simply delete the namespace where we put the app. Like this
kubectl delete namespace sock-shop
If you want to remove entire cluster and free up your workstation's RAM for some new work, you do with following command
[miki@latitude-e5470 vagrant]$ vagrant destroy -f
We have successfully installed the Kubernetes on CoreOS with Vagrant, tried on the test app and cleaned up the environment. With did this now for top 3 operating systems used for Kubernetes deployments. Ubuntu, CentOS and in this article, CoreOS. Thank you for reading and have a nice day.