I have created a k8s cluster and network, using 1 master and 2 nodes. However during pod (nginx) deployment, the deployment happens only on one server i.e. node1 and not on other server i.e. node2, as the result shows below o/p
[root@controller Kubernetes]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 10m 192.168.1.2 node1 <none> <none>
[root@controller Kubernetes]#
which means nginx is deployed on only node1 and not on node2
Result of the nodes joining the master
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
controller Ready master 142m v1.16.0 192.168.33.20 <none> CentOS Linux 7 (Core) 3.10.0-1062.1.1.el7.x86_64 docker://1.13.1
node1 Ready <none> 134m v1.16.0 192.168.33.10 <none> CentOS Linux 7 (Core) 3.10.0-1062.1.1.el7.x86_64 docker://1.13.1
node2 Ready <none> 46m v1.16.0 192.168.33.30 <none> CentOS Linux 7 (Core) 3.10.0-1062.1.1.el7.x86_64 docker://1.13.1
[root@controller Kubernetes]#
Pod file:
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
name: nginx-web-application
spec:
containers:
- name: nginx-container
image: nginx
I want to see the deployment happening on node2 as well when i run below command, can u please tell why it is not happening on both the nodes:
kubectl create -f pod.yml
2
Answers
Your setup creates a pod with one container on one of the nodes (which one is decided by kube-scheduler).
If you want to run that pod on each node use DaemonSet which ensures that a copy of a pod runs on each node.
Deployment with 2 or more replicas should work since you have two nodes if both of your nodes are capable of running that pod (look at kube-scheduler).
And last thing – you can use Taints and Tolerations. Easiest way would be to taint your
node1
to not allow shceduling pods on it (example from the documentation):A Pod is exactly one copy of a container (rarely, multiple tightly-coupled containers). It will run on exactly one node.
You almost never want to directly use a Pod; instead, prefer a higher-level controller object. Most often you’ll use a Deployment, which you can tell you want e.g. 3 replicas of a pod running somewhere in the cluster. If you actually need one copy running on each node (usually this is only needed for infrastructure-type pods) that’s the model of a DaemonSet.