Home  K8s   How to inst ...

How to install K8s and setup a cluster

Installing Kubernetes (K8s) and using it typically involves setting up a cluster, installing necessary tools, and deploying applications. Here’s a step-by-step guide for setting up a Kubernetes cluster using Minikube and managing it with kubectl.

Prerequisites

Step 1: Install Docker

Minikube requires a container or VM manager. Docker is a common choice.

  1. Install Docker:

Step 2: Install Minikube

Minikube sets up a local Kubernetes cluster.

  1. Download Minikube:

    • Windows:
      choco install minikube
      
    • Mac:
      brew install minikube
      
    • Linux:
      curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
      sudo install minikube-linux-amd64 /usr/local/bin/minikube
      
  2. Start Minikube:

    minikube start
    

Step 3: Install kubectl

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

  1. Download kubectl:

    • Windows:
      choco install kubernetes-cli
      
    • Mac:
      brew install kubectl
      
    • Linux:
      curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
      sudo install kubectl /usr/local/bin/kubectl
      
  2. Verify Installation:

    kubectl version --client
    

Step 4: Use Minikube and kubectl

  1. Check Minikube Status:

    minikube status
    
  2. Interact with the Cluster:

    • Get Cluster Info:
      kubectl cluster-info
      
    • List Nodes:
      kubectl get nodes
      
    • Deploy an Application:
      kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
      
    • Expose the Application:
      kubectl expose deployment hello-minikube --type=NodePort --port=8080
      
    • Get the URL of the Service:
      minikube service hello-minikube --url
      

Step 5: Access the Kubernetes Dashboard

  1. Launch the Dashboard:
    minikube dashboard
    

Step 6: Clean Up

  1. Stop Minikube:

    minikube stop
    
  2. Delete Minikube Cluster:

    minikube delete
    

Using Kubernetes

Once your Kubernetes cluster is set up, you can deploy, manage, and scale your applications. Here are some additional commands and steps:

  1. Deploy a YAML file:

    kubectl apply -f <file>.yaml
    
  2. Check Pod Status:

    kubectl get pods
    
  3. View Logs of a Pod:

    kubectl logs <pod-name>
    
  4. Execute a Command in a Pod:

    kubectl exec -it <pod-name> -- /bin/bash
    
Published on: Jul 03, 2024, 04:58 AM  
 

Comments

Add your comment