Setup Kubernetes kubectl and Minikube on Ubuntu 22.04 LTS

Subham Pradhan
4 min readApr 2, 2024

--

Kubernetes has become the go-to container orchestration platform for deploying, managing, and scaling containerized applications. In this guide, we’ll walk you through the process of setting up your development environment on Ubuntu and getting started with Kubernetes using kubectl, Docker, and Minikube.

Installing kubectl

Kubectl is the command-line tool used to interact with Kubernetes clusters. Let’s start by installing kubectl on Ubuntu:

Installing Docker

Docker is a popular platform for building, shipping, and running applications in containers. Let’s install Docker on Ubuntu:

sudo apt update
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
sudo apt install -y apt-transport-https ca-certificates 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

To verify the installation, run:

sudo snap install kubectl --classic
kubectl version --client

Installing Minikube

Minikube is a tool that allows you to run Kubernetes clusters locally for development and testing purposes. Here’s how you can install Minikube on Ubuntu:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube version

Starting Minikube with Docker Driver

Now that we have Minikube installed, let’s start a Minikube cluster using the Docker driver:

minikube start --driver=docker
# If you encounter root privileges error, run:
minikube start --driver=docker --force
minikube status
kubectl cluster-info
kubectl config view
kubectl get nodes
kubectl get pods
minikube dashboard

Deploying an Application:

Let’s deploy a simple Nginx web server using kubectl:

kubectl create deployment my-nginx --image=nginx:latest
kubectl get deployment
kubectl get pods

Exposing the Service:

To expose the Nginx deployment, we can create a LoadBalancer service:

kubectl expose deployment my-nginx --port=80 --type=LoadBalancer
kubectl get services

Now you should see an external IP address assigned to the Nginx service, which you can use to access the deployed application.

Conclusion

In this guide, we’ve covered the installation and setup of kubectl, Docker, and Minikube on Ubuntu. We’ve also deployed a sample application and exposed it using a LoadBalancer service. This is just the beginning of your journey with Kubernetes, and there’s a lot more to explore and learn. Happy Kubernetes-ing!

--

--

Subham Pradhan

DevOps Engineer | CI/CD | K8S | Docker | Jenkins | Ansible | Git | Terraform | ArgoCD | Helm | Prometheus| Grafana |Kibana | Puppet | Chef | Azure | DevSecOps |