Kubernetes Installation Methods & Setup

Kubernetes Installation Methods & Setup

Week 5 #90Days of DevOps challenge #devops #trainwithshubham #kubernetes

K8s Installation Methods

Kubernetes is a popular open-source container orchestration tool used to automate the deployment, scaling, and management of containerized applications. There are several installation methods available to deploy Kubernetes depending on your requirements, including:

  1. Minikube:

    - It is ideal for someone who wants to install Kubernetes on their system but has a limited system resource. So the key takeaway point with minikube is that it doesn’t have a separate Kubernetes master and Kubernetes worker node architecture.

    - Here we get all Kubernetes components packaged together as an all-in-one setup. The single system acts as both master and worker nodes.

  2. kubeadm:

    - Kubeadm is a command-line tool that can be used to set up a Kubernetes cluster. It is a way to go if you need an actual real-time setup.

    - It can be done using the Kubeadm tool. It can be used to set up multi-node Kubernetes clusters. It is one of the most popular installation methods for Kubernetes.

    - Depending upon the system resource you have you can create multiple VMs. Then you can configure Kubernetes master and node components.

    - In case your system resources are limited, it is recommended to use cloud-based VMs.

  3. Kubernetes on cloud platforms:

    - Several cloud providers offer managed Kubernetes services, such as Amazon EKS, Microsoft AKS, and Google Kubernetes Engine (GKE).

    - These services allow you to deploy and manage Kubernetes clusters without worrying about the underlying infrastructure.

  4. Kubernetes distributions:

    - There are several Kubernetes distributions available, such as OpenShift, Rancher, and Red Hat Kubernetes. These distributions come with additional features and tools to help you manage your Kubernetes clusters.

  5. Kubernetes installers:

    - There are several Kubernetes installers available, such as Kubespray and Kops, which automate the installation process and can help you set up a Kubernetes cluster quickly.

  6. Play-with-K8s:

    - Play-with-K8s (PWK) is a web-based learning and testing platform for Kubernetes. It provides users with a Kubernetes environment in which they can experiment and learn about Kubernetes without needing to set up their cluster.

    - PWK is a free and open-source tool that is maintained by the Kubernetes community. It runs on the Docker platform and uses Docker containers to create and manage Kubernetes clusters.

    - One of the advantages of PWK is that it is easy to set up and use. Users do not need to have any prior experience with Kubernetes or Docker to get started with PWK.

When choosing an installation method, consider factors such as ease of use, scalability, security, and support options.

Kubeadm Setup

To install the Kubeadm tool visit here .

Go through the below steps of installation based on your requirements.

  1. Execute the below commands on both the Master and Worker node.

     #########   Both Master & Worker Node   
     sudo apt update -y
     sudo apt install docker.io -y
    
     sudo systemctl start docker
     sudo systemctl enable docker
    
     sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
    
     echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
    
     sudo apt update -y
     sudo apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y
    
  2. Execute the below commands on the Master node.

     sudo su
     kubeadm init
    
       mkdir -p $HOME/.kube
       sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
       sudo chown $(id -u):$(id -g) $HOME/.kube/config
    
     kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
    
     kubeadm token create --print-join-command
    
  3. Execute the below commands on the Worker node.

     sudo su
     kubeadm reset pre-flight checks
     #Paste the output(token) of Join command from master to worker node with `--v=5`
    
  4. Execute the below commands on the Master node.

     kubectl get nodes
    

    Note: Create Inbound rule on master with port given in token(output of join command on master)

Kubectl Commands

Getting Resources:

  1. Getting all Resources: This command is showing all available resources.

  2. Getting Nodes: This command shows only the available nodes.

  3. Getting Pods: This command shows only the available pods.

  4. Getting Services: This command shows only the available services.

    Creating Resources:

  5. Creating Deployment: The command creates a deployment named nginx-depl using image Nginx.

  6. Creating service: The command in the creates a service of type node port named nginx and it is exposed on port 80 of the local machine.

    Updating Resources:

  7. Updating Deployment: The command in the below output opens a vim-like editor in the terminal to edit the Nginx-depl deployment config file.

  8. Updating Service: The command opens a vim-like editor in the terminal to edit the Nginx service config file.

    Deleting Resources:

  9. Deleting Deployment: The command deletes a deployment named nginx-depl.

  10. Deleting Service: The command deletes a service named Nginx.

    Using Configuration File for CRUD:

  11. Applying a Config file: The command creates the resource if it does not exist or updates it if it already exists according to the configuration in the YAML file mentioned after the -f flag.

    $ kubectl apply -f [file-name]

    kubectl apply -f nginx-service.yaml
    
  12. Deleting using Config file: The command deletes the resource that was created using the YAML config file mentioned after the -f flag/

    $ kubectl delete -f [file-name]

    kubectl delete -f nginx-service.yaml
    

    Debugging Pods:

  13. Viewing Logs of a Pod: The command shows the logs of the pod mentioned once the pod started.

    kubectl logs [pod-name]
    
  14. Get an Interactive terminal for a pod: The command starts an interactive terminal of the Nginx pod so that we can control the pod directly through its terminal.

    kubectl exec -it [pod-name] — bin/bash
    
  15. Get info about a Resource: The command gives details about the nginx deployment

    kubectl describe <resource_type> [resource-name]
    

Thank you, Readers, for giving your precious time to read my first-ever blog. I am open to your valuable suggestions to upskill myself. Glad to share my learnings of #DevOps in the #trainwithshubham community during the #90daysofdevops challenge. Your appreciation will motivate me to learn and share upcoming learnings.