0
votes

Environment Details:

Kubernetes version: `v1.20.2`
Master Node: `Bare Metal/Host OS: CentOS 7`
Worker Node: `VM/Host OS: CentOS 7`

I have installed & configured the Kubernetes cluster, the Master node on the bare metal server & the worker node on windows server 2012 HyperV VM. Both master and worker nodes have the same Kubernetes version ( v1.20.2) & centos7. Successfully joined worker node to master, below is the get nodes status.

$ kubectl get nodes

**NAME             STATUS ROLES               AGE  VERSION

k8s-worker-node1 Ready  <none>              2d2h v1.20.2

master-node      Ready control-plane,master 3d4h v1.20.2**

While creating a deployment on the worker node I am getting the below error message.

On worker node, I issued the following command.

$ kubectl create deployment nginx-depl --image=nginx

Error message is:
error: failed to create deployment: Post “http://localhost:8080/apis/apps/v1/namespaces/default/deployments?fieldManager=kubectl-create”: dial tcp: lookup localhost on 8.8.8.8:53: no such host

please help me to resolve this issue as I am not able to understand what is the problem.

1
First of all try to run kubectl command from master node but if you still have this problem please answer to my questions: Did you modify your /etc/hosts file ? Do you have localhost entry in /etc/hosts file ? Can you run command: ping localhost from your problematic node ?matt_j
Hi, actually I was executing from the worker node instead of the master node. Yes, I had made the entry in /etc/hosts file. As suggested by user skogul1997 i executed kubectl create deployment on master node and deployment created. BTW thank you for your comment.Imran Shaikh

1 Answers

0
votes

It seems that you are issuing the kubectl create deployment command on the worker node. This won't work because the kubectl command communicates with the kub-apiserver for cluster communication. Since the apiserver does not run on the worker node executing the command on it will raise an error.

Instead execute the same kubectl command on the master node as a non-root user with the following additional commands,

$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ kubectl create deployment nginx-depl --image=nginx