Kubernetes – Kubernetes Installation Guide

Introduction

Deploying applications to Kubernetes can be done efficiently using local machine solutions, enabling developers to configure and run Kubernetes clusters in their local environments. This allows for thorough testing throughout the development phases without the need for significant investment in cluster management.

Docker Desktop

Docker Desktop for Windows and Mac includes a built-in Kubernetes server that runs on the local host. This enables the testing of Docker workloads on Kubernetes.

Enabling Kubernetes in Docker Desktop

  1. Enable Kubernetes:
    • Open Docker Desktop settings.
    • Select the option to enable Kubernetes.
  2. Setup:
    • Docker Desktop will instantiate the required images to run the Kubernetes server as containers.
    • The kubectl.exe command will be installed in the path. If you have kubectl already installed for another environment (e.g., Minikube), change the context to point to docker-desktop: sh kubectl config use-context docker-desktop
  3. Status and Management:
    • When Kubernetes is enabled, a status bar item will appear at the bottom right of the Docker Desktop Settings dialog.
    • The status of Kubernetes can be viewed in the Docker menu.
  4. Reset and Disable:
    • To delete all stacks and resources, select “Reset Kubernetes Cluster.”
    • To disable Kubernetes, uncheck the “Enable Kubernetes” box. This will stop and remove the Kubernetes containers and remove the /usr/local/bin/kubectl command.

Note: Kubernetes containers are hidden by default from commands like docker service ls. To view them, enable “Show system containers (advanced)” under the Kubernetes menu.

Testing the Installation

  1. Open a command prompt or terminal window.
  2. Run the following commands to verify Kubernetes is running: sh kubectl version kubectl cluster-info Kubernetes should report that both the Kubernetes master and KubeDNS are running on localhost:6443.
  3. To view the current context: sh kubectl config get-contexts Configuration files are located at:
    • Windows: C:\\\\Users\\\\<user-name>\\\\.kube\\\\config
    • Linux: /home/<username>/.kube/config
  4. To set the current context: sh kubectl config use-context minikube
  5. To view cluster and context configuration: sh kubectl config view

Installing Minikube on Ubuntu

Prerequisites

  1. Update System and Install Packages: sh sudo apt-get update -y sudo apt-get upgrade -y sudo apt-get install curl apt-transport-https
  2. Install VirtualBox Hypervisor: sh sudo apt install virtualbox virtualbox-ext-pack

Minikube Installation

  1. Download and Install Minikube: sh wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo cp minikube-linux-amd64 /usr/local/bin/minikube sudo chmod 755 /usr/local/bin/minikube minikube version
  2. Install Kubectl: sh curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl chmod +x ./kubectl sudo mv ./kubectl /usr/local/bin/kubectl kubectl version -o json
  3. Start Minikube: sh minikube start kubectl config view kubectl cluster-info kubectl get nodes kubectl get pods
  4. Other Minikube Commands: sh minikube status minikube stop minikube delete minikube addons list minikube dashboard

Installing Minikube on Windows

Prerequisites

  • Hypervisor:
    • Minikube supports both Type-1 (e.g., Hyper-V) and Type-2 (e.g., VirtualBox) hypervisors.
    • Hyper-V is available on Windows 10 Enterprise, Professional, and Education editions.

Installation Steps

  1. Install a Hypervisor:
    • If not already installed, install Hyper-V or VirtualBox.
  2. Install Chocolatey:
    • Open PowerShell in administrative mode and run: sh Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1‘))
  3. Install Kubectl:
    • Install using Chocolatey: sh choco install kubernetes-cli
  4. Install Minikube:
    • Install using Chocolatey: sh choco install minikube
    • Restart the CLI session to update the path.
  5. Start Minikube: sh minikube start minikube status minikube stop
  6. Redirect Docker CLI to Minikube Host (if Docker Desktop is installed): sh echo $(minikube docker-env) eval $(minikube docker-env) docker ps

By following these steps, you can set up and test Kubernetes using either Docker Desktop or Minikube on your local machine, enabling a robust development environment for Kubernetes-based applications.

-Thank you, happy coding !!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *