Requirement :
1. 3 CentOS 7.4 any or 3 Ubuntu 16.04 server
2. Install kubeadm / kubelet / kubectl in all three server
3. swap off in all three servers. [ permanent off ]
4. Docker latest installation in all three server
5. enable all service on boot [ kubelet , kubectl , kubeadm , ]
For this blog, i am using CentOS 7.4 server
After that check all the services are running or not,
# systemctl status kubelet
# systemctl status kube
Now disable swap,
# swapoff -a
Disable permanently
Before creation of cluster, you need to create connectivity between master and different nodes using kubeadm command [ using tokens ]. For this blog, i am skipping this step.
Now we will check slave nodes present in master node
you will see three name :
master1.local
node1.local
node2.local
Now check services present in Kubernetes,
# kubectl get svc
Now check "Docker process " in master and other nodes,
In master node,
# docker ps
you will see that lots of container created in docker because of kubernetes storage, networking, proxy and other parameters.
In node 1 and node2 ,
For this blog, i used weave network for Kubernetes internal connectivity for pods.
Now we will deploy Nginx in slave node using master cluster and work as load balancer.
We will create and run Nginx image and create replicate, for this we will deploy 2 replicate pods.
# kubectl run nginx --image=nginx:latest --replicas=2
Now check the deployment,
# kubectl get deployment
To find out what Kubernetes created you can describe the deployment process.
The description includes how many replicas are available, labels specified and the events associated with the deployment. These events will highlight any problems and errors that might have occurred.
Now check the IP address of master,
# ip addr
Now we will expose that service to particular IP address and port.
# kubectl expose deployment nginx --external-ip="192.168.0.100" --port=80 --target-port=80
Now check services for port and IP address..
# kubectl get svc
Now check pods details using kubectl command
# kubectl get pods
Now check docker container for Nginx,
For master,
# docker ps | grep nginx
you will see replica pod containers didn't set in master node.
For node1
# docker ps | grep nginx
and for node2,
# docker ps | grep nginx
Now, using master node IP address.
Master Node IP address : 192.168.0.100
using curl command check,
# curl http://192.168.0.100:80
Now go to browser and check for IP address of server.
Now, we will delete any container present in docker of any node.
before deleting we will use watch command to check the status of pods,
# watch kubectl get pods
after that,
Now delete any of docker container related to nginx,
# docker ps | grep nginx
# docker rm -f container_id
Now check the watch command for pods,
# kubectl ger pods
you will see that after deleting container related to Nginx in any node.
It will again create Nginx container in that node.
after few seconds, status of new Nginx pod is running,
Now again go to web and check for server,
END
Comments
Post a Comment