Unless you've had your head buried in a pile of Cat5 cables, you know what Kubernetes is. For those who are neck deep in cabling, Kubernetes is an open-source system used for automating the deployment, scaling, and management of containerized applications. Kubernetes is enterprise-ready and can be installed on various platforms.
However (isn't there always an however?), the installation of Kubernetes can sometimes be a challenge. That's why I'm here. I want to show you how you can easily and quickly install Kubernetes on Ubuntu, initialize your master, join a node to your master, and deploy a service on the cluster.
I'll be demonstrating this with the Ubuntu platform (specifically one instance of Ubuntu Server 16.04 and one of Ubuntu Desktop 17.10).
The first thing you must do is install the necessary dependencies. This will be done on all machines that will join the Kubernetes cluster. The first piece to be install is apt-transport-https (a package that allows using https as well as http in apt repository sources). This can be installed with the following command:
sudo apt-get update && apt-get install -y apt-transport-https
Our next dependency is Docker. Our Kubernetes installation will depend upon this, so install it with:
sudo apt install docker.io
Once that completes, start and enable the Docker service with the commands
sudo systemctl start docker sudo systemctl enable docker
You're now ready to install Kubernetes.
Installing the necessary components for Kubernetes is simple. Again, what we're going to install below must be installed on all machines that will be joining the cluster.
Our first step is to download and add the key for the Kubernetes install. Back at the terminal, issue the following command:
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add
Next add a repository by creating the file /etc/apt/sources.list.d/kubernetes.list and enter the following content:
deb http://apt.kubernetes.io/ kubernetes-xenial main
Save and close that file. Install Kubernetes with the following commands:
apt-get update apt-get install -y kubelet kubeadm kubectl kubernetes-cni
SEE: Special report: The cloud v. data center decision (free PDF) (TechRepublic)
Initialize your master
With everything installed, go to the machine that will serve as the Kubernetes master and issue the command:
sudo kubeadm init
When this completes, you'll be presented with the exact command you need to join the nodes to the master ( Figure A).
Before you join a node, you need to issue the following commands (as a regular user):
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Deploying a pod network
You must deploy a pod network before anything will actually function properly. I'll demonstrate this by installing the Flannel pod network. This can be done with two commands (run on the master):
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel-rbac.yml
Issue the command sudo kubectl get pods —all-namespaces to see that the pod network has been deployed (Figure B).
Joining a node
With everything in place, you are ready to join the node to the master. To do this, go to the node's terminal and issue the command:
sudo kubeadm join --token TOKEN MASTER_IP:6443
Where TOKEN is the token you were presented after initializing the master and MASTER_IP is the IP address of the master.
Once the node has joined, go back to the master and issue the command sudo kubectl get nodes to see the node has successfully joined (Figure C).
Deploying a service
At this point, you are ready to deploy a service on your Kubernetes cluster. To deploy an NGINX service (and expose the service on port 80), run the following commands (from the master):
sudo kubectl run --image=nginx nginx-app --port=80 --env="DOMAIN=cluster" sudo kubectl expose deployment nginx-app --port=80 --name=nginx-http
If you go to your node and issue the command sudo docker ps -a, you should see the service listed (Figure D).
Your Kubernetes cluster is ready
You now have a basic Kubernetes cluster, consisting of a master and a single node. Of course you can scale your cluster by installing and adding more nodes. With these instructions, that should now be easy peasy.
- Kubernetes: The smart person's guide (TechRepublic)
- How to deploy CoreOS as a virtual machine (TechRepublic)
- How to install the necessary components for a Kubernetes cluster on Ubuntu Linux (TechRepublic)
- How to create and manage Docker networks (TechRepublic)
- The Complete DevOps & Deployment Technologies Bundle (TechRepublic Academy)
- How to get the Kubernetes help you need (ZDNet)
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.