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
- Enable Kubernetes:
- Open Docker Desktop settings.
- Select the option to enable Kubernetes.
- 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
- 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.
- 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
- Open a command prompt or terminal window.
- 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.
- 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
- To set the current context: sh kubectl config use-context minikube
- To view cluster and context configuration: sh kubectl config view
Installing Minikube on Ubuntu
Prerequisites
- Update System and Install Packages: sh sudo apt-get update -y sudo apt-get upgrade -y sudo apt-get install curl apt-transport-https
- Install VirtualBox Hypervisor: sh sudo apt install virtualbox virtualbox-ext-pack
Minikube Installation
- 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
- 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
- Start Minikube: sh minikube start kubectl config view kubectl cluster-info kubectl get nodes kubectl get pods
- 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
- Install a Hypervisor:
- If not already installed, install Hyper-V or VirtualBox.
- 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‘))
- Install Kubectl:
- Install using Chocolatey: sh choco install kubernetes-cli
- Install Minikube:
- Install using Chocolatey: sh choco install minikube
- Restart the CLI session to update the path.
- Start Minikube: sh minikube start minikube status minikube stop
- 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 !!