Edited 4 weeks ago by ExtremeHow Editorial Team
KubernetesContainersDevOpsClustersOrchestrationApplication ManagementScalabilityConfigurationDeploymentServer Management
This content is available in 7 different language
Kubernetes, often referred to as K8s, is an open-source platform designed to automate the deployment, scaling, and operation of application containers. It provides a framework that enables you to run distributed systems flexibly. Kubernetes manages the work your applications perform based on the resources available on your cluster, optimally distributes load, and manages failure recovery.
Before starting the installation of Kubernetes on Linux, make sure you have the following prerequisites:
Docker is the runtime that Kubernetes uses to manage containers. It forms the basis on which Kubernetes works. Follow these steps to install Docker on your Linux system:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -cs) stable"
sudo apt-get update sudo apt-get install docker-ce
sudo systemctl start docker sudo systemctl enable docker
Verify the Docker installation by checking its version:
docker --version
To install Kubernetes, you need to add its official repository to your package manager:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
The three fundamental components of Kubernetes are kubelet, kubeadm and kubectl. Here's how to install them:
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Once Kubernetes is installed, it's time to configure the system appropriately:
Kubernetes does not work when swap memory is enabled. Use the following to disable swap on your system:
sudo swapoff -a
To make the change permanent across reboots, comment out the swap line in /etc/fstab
.
Make sure these network settings are configured correctly:
net.bridge.bridge-nf-call-iptables=1
:sudo sysctl net.bridge.bridge-nf-call-iptables=1
sysctl -p
.We use kubeadm
to set up a master node - the control plane for your Kubernetes cluster:
sudo kubeadm init
kubectl
configuration. This usually includes:mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
root
, replace $HOME
with /root
or /home/<your-username>
.Install the Pod Network plugin to allow communication between pods. Here is an example using Flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Check the status of your nodes:
kubectl get nodes
Deploying your first application is simple. Let's deploy a simple nginx server:
kubectl run nginx --image=nginx --port=80
To expose the deployment as a service accessible from outside the cluster:
kubectl expose deployment nginx --type=NodePort
Get details about your deployment and service:
kubectl get deployments kubectl get services
NodePort
of the service will give you a port to access the nginx server, which you can access using your server's IP address and the given port.
One of the significant advantages of Kubernetes is its ability to easily scale applications. If your nginx server needs to handle more load, you can scale it:
kubectl scale deployment nginx --replicas=3
Check Status:
kubectl get pods -o wide
After trying out Kubernetes features, you may want to clean up the demo environment:
kubectl delete service nginx kubectl delete deployment nginx
With this guide, you've gotten started installing and using Kubernetes on Linux. This setup gives you a basic understanding of Kubernetes, focusing on essential components like kubeadm, kubelet, and the ability to deploy and manage simple applications. From here, you can explore more advanced Kubernetes concepts, configuration, and management techniques to harness the full power of Kubernetes in your infrastructure.
If you find anything wrong with the article content, you can