Kubernetes is a popular open-source platform for deploying and managing containerized applications. It provides powerful tools for scheduling and deploying containers across a cluster of servers. In this article, we will show you how to deploy Kubernetes using Kubeadm on CentOS 7.
Before you can deploy Kubernetes, you need to make sure that your CentOS 7 system is up to date. Run the following commands to update your system:
sudo yum update
sudo reboot
Next, you need to install Docker, which is the container runtime that Kubernetes uses to run containers. To do this, run the following command:
sudo yum install -y docker
Once Docker is installed, start the Docker service and enable it to start at boot time by running the following commands:
sudo systemctl start docker
sudo systemctl enable docker
Now, you need to install the Kubernetes command-line interface (CLI) tool, kubectl, which you will use to manage your Kubernetes cluster. To do this, run the following command:
sudo yum install -y kubectl
With kubectl installed, you are now ready to install Kubeadm, which is the tool that you will use to deploy your Kubernetes cluster. To do this, run the following command:
sudo yum install -y kubelet kubeadm
Once Kubeadm is installed, you can use it to initialize your Kubernetes cluster. To do this, run the following command:
sudo kubeadm init
This command will initialize the Kubernetes control plane on your system, and it will print out a kubeadm join command that you will need to use to add worker nodes to your cluster.
To start using your Kubernetes cluster, you need to configure your kubectl command-line tool to connect to it. To do this, run the following command:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Now, you can check the status of your Kubernetes cluster by running the following command:
kubectl get nodes
This command should show you the status of your Kubernetes control plane node.
If you want to add worker nodes to your Kubernetes cluster, you can use the kubeadm join command that was printed out when you initialized the cluster. Run this command on each of your worker nodes to add them to the cluster.
Once you have added your worker nodes, you can verify that they are connected to the cluster by running the **`kubectl get nodes`** command again. This time, you should see your worker nodes listed along with the control plane node.
Here are a few examples of how to use it:
- To check the status of your Kubernetes cluster, you can run the
kubectl get nodes
command, which will show you a list of the nodes in your cluster, along with their status. - To deploy a new application to your Kubernetes cluster, you can use the
kubectl create
command. For example, if you have a YAML file that describes your application, you can use thekubectl create -f
command to create the resources defined in that file. - To view the logs for a specific pod in your Kubernetes cluster, you can use the
kubectl logs
command. For example, if your pod is named “my-pod”, you can runkubectl logs my-pod
to see the logs for that pod. - To access a shell on a specific pod in your Kubernetes cluster, you can use the
kubectl exec
command. For example, if your pod is named “my-pod”, you can runkubectl exec -it my-pod bash
to open a shell on that pod. - To delete a resource from your Kubernetes cluster, you can use the
kubectl delete
command. For example, if you want to delete a deployment named “my-deployment”, you can runkubectl delete deployment my-deployment
.
These are just a few examples of how to use kubectl. For a complete list of commands and options, you can run kubectl -h
to see the full usage information.
Congratulations! You have successfully deployed Kubernetes on CentOS 7 using Kubeadm. You can now start deploying your containerized applications to your Kubernetes cluster.