Kubernetes is an open-source container-orchestration tool for automating the application deployment, scaling, and management. It provides a platform that automates Linux container operations. It eliminates many of the manual processes involved in deploying and scaling containerized applications.
You can cluster together groups of hosts running Linux containers, and Kubernetes helps you easily and efficiently manage those clusters. These clusters can span hosts across public, private, or hybrid clouds.
For this very reason, Kubernetes is an ideal platform for hosting cloud-native applications that require rapid scaling. It was originally designed by Google, and is now maintained by the Cloud Native Computing Foundation.
Stpes to Set up a Kubernetes Cluster on Ubuntu 19.04 :
Installing Docker
$ sudo apt install docker.io
Checking Docker Version
$ docker –version
Enable docker
$ sudo systemctl enable docker
The first step is to download and add the key for the Kubernetes install. Add the Kubernetes signing key on both the nodes :
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
If curl is not installed on your system, run below command:
$ sudo apt-get install curl
Add Xenial Kubernetes Repository on both the nodes
$ sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
Installing virtualbox on Ubuntu
$ sudo apt-get install -y virtualbox virtualbox-ext-pack
Install kubectl, which you use to interact with the Kubernetes cluster.
$ sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni
If above binaries are not installed together, install them one by one.
Download and install minikube, which runs a single node Kubernetes cluster on your machine.
Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows.
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.28.2/minikube-linux-amd64
or
https://github.com/kubernetes/minikube/releases/tag/v1.3.1
or
$ snap install minikube
Snap path(if installed through snap):
$ sudo chmod +x /snap/bin/minikube
Now start up Minikube and use kubectl to find what version of Kubernetes you’re running on Ubuntu.
$ minikube start
Starting local Kubernetes cluster...
$ kubectl api-versions
Initialize your master
With everything installed, go to the machine that will serve as the Kubernetes master and issue the command:
sudo kubeadm init
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. This is demonstrated using 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/k8s-manifests/kube-flannel-rbac.yml
Use the following command in order to view the status of the network:
$ kubectl get pods –all-namespaces
Now when you see the status of the nodes, you will see that the master-node is ready:
$ sudo kubectl get nodes
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
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.
Now 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, Kubernetes cluster should be up and running !!
Pankaj
Comments
Post a Comment