kubernetes on Ubuntu 22.04

To create a Kubernetes cluster on Ubuntu 22.04, you can follow the steps outlined below:


Note: These instructions assume you have Ubuntu 22.04 installed on all nodes and have administrative access to them.


1. Update System Packages:

   ```

   sudo apt update

   sudo apt upgrade

   ```


2. Install Docker:

   ```

   sudo apt install docker.io

   ```


3. Enable and Start Docker:

   ```

   sudo systemctl enable docker

   sudo systemctl start docker

   ```


4. Install Kubernetes Components:

   ```

   sudo apt install -y apt-transport-https curl

   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

   sudo apt update

   sudo apt install -y kubelet kubeadm kubectl

   ```


5. Disable Swap:

   ```

   sudo swapoff -a

   sudo sed -i '/ swap / s/^/#/' /etc/fstab

   ```


6. Initialize the Cluster:

   On the master node, run the following command to initialize the cluster:

   ```

   sudo kubeadm init --pod-network-cidr=10.244.0.0/16

   ```

   Make a note of the join command displayed after the initialization completes.


7. Set Up the Kubernetes Configuration:

   ```

   mkdir -p $HOME/.kube

   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

   sudo chown $(id -u):$(id -g) $HOME/.kube/config

   ```


8. Install a Pod Network Addon:

   Choose a pod network add-on according to your preference. For example, you can use Flannel:

   ```

   kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

   ```


9. Join Worker Nodes:

   On each worker node, run the join command you noted earlier:

   ```

   sudo kubeadm join <master-node-ip>:<master-node-port> --token <token> --discovery-token-ca-cert-hash <hash>

   ```

   Replace `<master-node-ip>`, `<master-node-port>`, `<token>`, and `<hash>` with the appropriate values from the master node initialization output.


10. Verify Cluster Status:

    On the master node, run the following command to check the status of the cluster and the worker nodes:

    ```

    kubectl get nodes

    ```


Congratulations! You have successfully created a Kubernetes cluster on Ubuntu 22.04.