k8s

Kubernetes, often abbreviated as K8s, is an open-source system for automating the deployment, scaling, and management of containerized containerized applications in an open source system. The system was designed by Google and donated to the Cloud Native Computing Foundation (Linux Foundation). It is designed to provide a platform for automated deployment, scaling, and running application containers across host clusters. It supports a range of container tools, including Docker and others.

In this article, we will explain how to resolve the error dial tcp 127.0.0.1:10248: connect: connection refused when kubeadm init is initialized.

dial tcp 127.0.0.1:10248: connect: connection refused

If you are trying to run Kubernetes and trying to initialize the Kubernetes cluster using sudo kubeadm init, there is a high probability that you will get the following error.

1
2
[kubelet-check] It seems like the kubelet isn't running or healthy.
[kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp 127.0.0.1:10248: connect: connection refused.

The general idea is that connections to 127.0.0.1:10248 using the tcp protocol are being rejected. This is a cgroup driver issue. By default the Kubernetes cgroup driver is set to system, but docker is set to systemd. We need to change the Docker cgroup driver.

Use your favorite editor, but here in this tutorial use vim to create the configuration file /etc/docker/daemon.json and add the following line.

1
sudo vim /etc/docker/daemon.json
1
2
3
{
    "exec-opts": ["native.cgroupdriver=systemd"]
}

You can also create a configuration file using the following command. Note that the following command will rewrite your configuration file.

1
echo '{"exec-opts": ["native.cgroupdriver=systemd"]}' | sudo tee /etc/docker/daemon.json

In order for the configuration to take effect, you must restart docker and kubelet. you will run the following command to restart docker and kubelet.

1
2
3
systemctl daemon-reload
systemctl restart docker
systemctl restart kubelet

Now, let’s try to reinitialize a Kubernetes cluster again, by running the following command.

1
2
sudo kubeadm reset
sudo kubeadm init