Get your first hands-on kubernetes with minikube

Dheeraj jha
3 min readFeb 23, 2024

--

Photo by Growtika on Unsplash

If you are beginner, care to understand kubernetes components, and since its master slave architecture, practically it will be difficult to setup in single machine.

Minikube provides efficient environment for you to play with kubernetes and setup cluster on your windows, Linux or Mac environment.

Minikube quickly sets up a local Kubernetes cluster on macOS, Linux, and Windows. We proudly focus on helping application developers and new Kubernetes users.

To install minikube, your system requirement must be

  • 2 CPUs or more
  • 2GB of free memory
  • 20GB of free disk space
  • Internet connection
  • Container or virtual machine manager, such as docker engine installed and running. (How to install docker?)

Install Minikube

Follow instruction and execute command based on your OS and architecture selection as mentioned at https://minikube.sigs.k8s.io/docs/start/.

Important:

If kubernetes is not installed, run following command to setup

minikube kubectl -- get po -A

This will require your docker service to run, if having any issue, please follow instruction prompted.

To ruk kubectl command, you may need to create alias by running following command

alias kubectl="minikube kubectl --"

You can also add this to your environment variable to make this alias permanent.

Run Minikube dashboard

To run dashboard, run following command

minikube dashboard

This will give you dashboard URL like this

http://127.0.0.1:45349/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

If you are doing all these on local machine, just open this URL and you’ll be able to access kubernetes-dashboard.

If you are doing this on remote server, you can connect it via tunnel.(ask me in comment how you can do this)

You are all set to run kubectl command.

Basic CRUD operation with kubectl

This consists of basics operation with your deployments, which are:

  1. Create deployment
  2. Read/view deployment
  3. Edit/update deployment
  4. Delete a deployment

Lets dive and get details:

Create deployment

To create new deployment, you can run command

kubectl create deployment nginx-depl --image=nginx

Where

nginx-depl: is the name of deployment

image=nginx is name of image to pull or use to deploy.

2. Read/View deployments

To verify deployment is completed, run following command

kubectl get deployments

to get the pods of your deployment, you can run kubectl get pods

to view log of your deployment, run

kubectl logs {your-pod-name}

example:

kubectl logs nginx-depl-6777bffb6f-gkzvh

to login to your container, you can use following command

kubectl exec -it {pod-name} -- bin/bash

where

exec: execute
-it: interactive terminal
bin/bash: shell to be used

this will log you in to the container, you can run regular command and exit using exit command.

3. Editing your deployment

To edit the configuration of your deployment, you can run following command

kubectl edit deployment {deployment-name}

This will open a configuration file, which you can edit. Upon editing, kubectl will automatically replace new deployment based on configuration.

4. Deleting your deployment

To delete your pod, you can run simple command

kubectl delete deployment {deployment-name}

this will delete pod.

While you are performing all ops, you can keep eye on kubernetes-dashboard running on your browser and see your changes reflacting there.

On my next post, we will explore more. If you found this helpful, do share.

--

--

Dheeraj jha

DevOps Engineer | Team lead | AWS | Docker | CI/CD | Gitlab-CI