Rahul B:
Mock exam 2 ques 8 -
root@node01:/etc/kubernetes/manifests# kubectl run nginx-critical --image=nginx --dry-run=client -o yaml > nginx-critical.yaml
The connection to the server localhost:8080 was refused - did you specify the right host or port?
root@node01:/etc/kubernetes/manifests#
I am trying to create static pod on node01 . Also I have added the staticPodPath in kubelet config as /etc/kubernetes/manifests. Why do I get the error above? Am i missing something ?
Any help is appreciated
root@node01:/etc/kubernetes/manifests# kubectl get po
The connection to the server localhost:8080 was refused - did you specify the right host or port?
ankit singh:
kubectl wont create static pods
Amrut Chougale:
It could be because there is no config file on node01 under ~/.kube/config
. When you create a static pod, you can just place the yaml file under /etc/kubernetes/manifests/pod1.yaml
and kubelet will create pod on node01. But you can see the pod listed from controlplane node, listed as pod1_node01
. Isnt it ?
unnivkn:
Hi @Rahul B try this:
cd
pwd
/root
root@controlplane# kubectl run nginx-critical --image=nginx --dry-run=client -o yaml > nginx-critical.yaml
root@controlplane# cat nginx-critical.yaml
root@controlplane# ssh node01
root@node01# cat /var/lib/kubelet/config.yaml | grep -i staticPodPath:
eg: if it is –> /etc/kubernetes/manifests
root@node01# cd /etc/kubernetes/manifests
root@node01# ##copy above controlplane cat command output
root@node01# vim nginx-critical.yaml
root@node01# paste the content in the file & save
root@node01# exit ##exit from node01
root@controlplane# k get po -A
Rahul B:
@unnivkn Thank you . Yes this works when we copy from controlplane to nde01. But why cannot we run directly on node01 ?
Rahul B:
@Amrut Chougale Yes , you are right so is that expectation? with the name “-node01”
unnivkn:
Hi @Rahul B this question expects what I mentioned above. Else you can do this:
Amrut Chougale:
@Rahul B It is expected as you do not have config file on all nodes of the cluster, hence you can not be able to connect to kube-apiserver from node01.
Static pods are managed by kubelet hence you do not need config file on node01. If you are using imperative commands to create your yaml file then do it from controlplane node and copy it. Otherwise if you know syntax of yaml file and required fields for pod definition then you can just create on node01 and it will create that pod.
Gerard:
@Rahul B I did the below steps from the controlplane
- Generate yaml to create the pod: k run nginx-critical --image=nginx --dry-run=client -o yaml > nginx-critical.yaml
- Copy the file to node01: scp nginx-critical.yaml node01:/etc/kubernetes/manifests
- verify whether the static pod name nginx-critical-node01 is running: k get pods -A or k get pods nginx-critical-node01