Kubernets not working

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: 1.15.0
Cloud being used: (put bare-metal if not on a public cloud) : AWS
Installation method:
Host OS: Ubuntu 18.04
CNI and version:
CRI and version:

Whenever i am using kubectl commnads like k get nodes it returns : The connection to the server (Private IP ):6443 was refused - did you specify the right host or port?

Anyone have any solution ?

Hello,

Are you trying to access the cluster from master node or from your local system?
Most probably the apiserver advertised ip may be the private one. If you created the cluster using Kubeadm you can use following command to advertise it over public IP also.

kubeadm init --apiserver-cert-extra-sans=PrivateIP,PublicIP \
  --pod-network-cidr $CALICO_NETWORK \
  --apiserver-advertise-address=PrivateIP

Here I am using Calico Pod network, change accordingly.

Thank You,
Praveen

while i run the first command it shows after few seconds : Initial timeout of 40s passed.

I1009 12:28:45.860954 17106 version.go:248] remote version is much newer: v1.16.1; falling back to: stable-1.15
[init] Using Kubernetes version: v1.15.4
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR IsPrivilegedUser]: user is not running as root
[preflight] If you know what you are doing, you can make a check non-fatal with --ignore-preflight-errors=...
ubuntu@ip-private ip:/etc/kubernetes$ sudo kubeadm init --apiserver-cert-extra-sans=private ip,publc ip
I1009 12:29:22.649044 17531 version.go:248] remote version is much newer: v1.16.1; falling back to: stable-1.15
[init] Using Kubernetes version: v1.15.4
[preflight] Running pre-flight checks
[WARNING IsDockerSystemdCheck]: detected “cgroupfs” as the Docker cgroup driver. The recommended driver is “systemd”. Please follow the guide at https://kubernetes.io/docs/setup/cri/
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using ‘kubeadm config images pull’
[kubelet-start] Writing kubelet environment file with flags to file “/var/lib/kubelet/kubeadm-flags.env”
[kubelet-start] Writing kubelet configuration to file “/var/lib/kubelet/config.yaml”
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder “/etc/kubernetes/pki”
[certs] Generating “etcd/ca” certificate and key
[certs] Generating “apiserver-etcd-client” certificate and key
[certs] Generating “etcd/server” certificate and key
[certs] etcd/server serving cert is signed for DNS names [ip-private ip localhost] and IPs [private ip 127.0.0.1 ::1]
[certs] Generating “etcd/healthcheck-client” certificate and key
[certs] Generating “etcd/peer” certificate and key
[certs] etcd/peer serving cert is signed for DNS names [ip-private ip localhost] and IPs [private ip 127.0.0.1 ::1]
[certs] Generating “front-proxy-ca” certificate and key
[certs] Generating “front-proxy-client” certificate and key
[certs] Generating “ca” certificate and key
[certs] Generating “apiserver” certificate and key
[certs] apiserver serving cert is signed for DNS names [ip-private ip kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 private ip private ip public ip]
[certs] Generating “apiserver-kubelet-client” certificate and key
[certs] Generating “sa” key and public key
[kubeconfig] Using kubeconfig folder “/etc/kubernetes”
[kubeconfig] Writing “admin.conf” kubeconfig file
[kubeconfig] Writing “kubelet.conf” kubeconfig file
[kubeconfig] Writing “controller-manager.conf” kubeconfig file
[kubeconfig] Writing “scheduler.conf” kubeconfig file
[control-plane] Using manifest folder “/etc/kubernetes/manifests”
[control-plane] Creating static Pod manifest for “kube-apiserver”
[control-plane] Creating static Pod manifest for “kube-controller-manager”
[control-plane] Creating static Pod manifest for “kube-scheduler”
[etcd] Creating static Pod manifest for local etcd in “/etc/kubernetes/manifests”
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory “/etc/kubernetes/manifests”. This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.

Hi everyone,

So, When your cluster init process freeze or broken? After that [kubelet-check] Initial timeout of 40s passed.

There are more information in your syslog? Do you receive some messages in your terminal before fail?

You need to replace public and private ip with your corresponding public and private ip.

In previous comment it was written to advertise using privateIP, which is wrong, please use below format.

kubeadm init --apiserver-cert-extra-sans=PrivateIP,PublicIP
–pod-network-cidr $CALICO_NETWORK
–apiserver-advertise-address=PublicIP

example:

export  CALICO_NETWORK=192.168.0.0/16
kubeadm init --apiserver-cert-extra-sans=172.31.18.58,18.219.161.116 \
  --pod-network-cidr $CALICO_NETWORK \
  --apiserver-advertise-address=18.219.161.116

Since you already configured the cluster using kubeadm, first do a kubeadm reset, then run above command.

Are you trying to access the cluster from the master node or from your local system?

If you were running kubectl command from master node, you will get output evenif API server is not advertised over public IP.

Reff: kubeadm init - Kubernetes