In the rapidly evolving landscape of containerization, Kubernetes and Docker often go hand in hand. While Docker provides a platform for creating, deploying, and running containers, Kubernetes offers a robust orchestration system for managing these containers at scale. This article will guide you through the process of installing Kubernetes on a Docker host, enabling you to leverage the power of both technologies together.
Prerequisites
Before we begin, ensure you have the following prerequisites in place:
- A Docker host with a Linux distribution (e.g., Ubuntu, CentOS) or a macOS/Windows machine with Docker Desktop installed.
- Docker CE (Community Edition) installed and running on your Docker host.
- Sudo privileges on your Docker host.
Installing Docker
If you haven't already, install Docker CE on your Docker host. For Ubuntu, use the following commands:

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
For CentOS, use:
sudo yum install docker-ce docker-ce-cli containerd.io
Setting Up the Docker Host
To use your Docker host as a Kubernetes node, you'll need to install a few additional packages:
- Kubelet: The primary "node agent" that runs on each node.
- Kubeadm: A command-line tool that helps you set up a local Kubernetes cluster.
- Kubectl: A command-line interface for running commands on your cluster.
Install these packages using the following commands:

sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <(echo "deb http://apt.kubernetes.io/ kubernetes-xenial main") | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Initializing the Kubernetes Cluster
Now that you have the necessary packages installed, you can initialize your Kubernetes cluster using kubeadm. Run the following command to start the process:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
The output will provide you with a command to join worker nodes to your cluster. Save this command for later use.
Setting Up the Kubernetes Configuration
To use kubectl on your Docker host, you'll need to set up a kubeconfig file:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Installing a Pod Network Add-on
Kubernetes requires a pod network to function correctly. Install a pod network add-on using the following command:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Verifying the Cluster
To verify that your Kubernetes cluster is up and running, run the following command:
kubectl get nodes
You should see your Docker host listed as a node in the cluster.
Joining Worker Nodes
To add more nodes to your cluster, run the command provided during the kubeadm init process on each worker node. Once complete, run the following command on your Docker host to verify the new nodes:
kubectl get nodes
Congratulations! You have successfully installed Kubernetes on your Docker host and created a functioning cluster. You can now proceed to deploy your applications using Kubernetes.






















