Kubernetes Installation Guide

Prerequisites

Before installing Kubernetes, understand the basic requirements:

System Requirements

  • Linux is the preferred operating system for running the Kubernetes control plane
  • Within your cluster you can run applications on Linux or other operating systems, including Windows
  • An operating system that supports container runtime is required

Choosing Installation Type

When installing Kubernetes, choose an installation type based on:

  • Ease of maintenance
  • Security
  • Control
  • Available resources
  • Expertise required to operate and manage a cluster

Installation Methods

If you're learning Kubernetes, use tools supported by the Kubernetes community or ecosystem tools to set up a cluster on your local machine:

Minikube

Minikube is a lightweight Kubernetes implementation that creates a single-node cluster on your local machine. Ideal for learning and small-scale testing.

Installation steps:

  1. Install Minikube
  2. Install kubectl (Kubernetes command-line tool)
  3. Start Minikube cluster

Kind

Kind (Kubernetes in Docker) is another tool for creating local Kubernetes clusters, using Docker containers to simulate nodes.

Production Environment

For production environments, consider these options:

kubeadm

The officially supported tool for deploying Kubernetes. Creates secure clusters following best practices.

Basic steps:

  1. Prepare servers (install OS, configure network)
  2. Install container runtime (containerd or Docker)
  3. Install kubeadm, kubelet, and kubectl
  4. Initialize cluster with kubeadm
  5. Configure network plugin (Calico, Cilium, etc.)
  6. Join worker nodes

Managed Services

If you don't want to manage a Kubernetes cluster yourself, consider managed services:

  • Amazon EKS (Elastic Kubernetes Service)
  • Google GKE (Google Kubernetes Engine)
  • Azure AKS (Azure Kubernetes Service)
  • Alibaba Cloud ACK
  • Tencent Cloud TKE

Other Solutions

There are also standardized and custom solutions across a wide range of cloud and bare metal environments.

Tool Installation

Installing kubectl

kubectl is the command-line tool for interacting with Kubernetes clusters.

Linux installation:

# Download latest version
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# Add execute permissions
chmod +x kubectl

# Move to system path
sudo mv kubectl /usr/local/bin/

Installing kubeadm

# Update apt package index
sudo apt-get update

# Install dependencies
sudo apt-get install -y apt-transport-https ca-certificates curl

# Add Kubernetes APT repository
echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

# Update and install
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

Cluster Initialization

Creating a Cluster with kubeadm

  1. Initialize the control plane node:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
  1. Configure kubectl:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
  1. Install network plugin (Flannel as example):
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  1. Join worker nodes:
# Run on each worker node the command from init output
kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>

Verifying Installation

Check cluster status:

# View nodes
kubectl get nodes

# View Pods
kubectl get pods --all-namespaces

If all components are in Running state, the cluster is successfully installed.

Uninstallation

If you need to uninstall Kubernetes:

# Stop all Kubernetes services
sudo kubeadm reset

# Remove configuration files
sudo rm -rf ~/.kube /etc/kubernetes /var/lib/etcd

# Uninstall packages
sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni etcd

Important Notes

  1. Container Runtime Selection: Choose an appropriate container runtime for your new cluster
  2. Resource Planning: Allocate CPU and memory resources reasonably based on workloads
  3. Network Planning: Plan Pod and Service network CIDRs in advance
  4. Security Hardening: Configure authentication, authorization, and network policies for production
  5. High Availability: Configure multi-control plane clusters for production environments