Getting Started with Minikube: Essential Commands

Minikube is a powerful tool that lets you run a single-node Kubernetes cluster locally on your machine. It's perfect for development, testing, and learning Kubernetes. In this article, we'll explore the essential Minikube commands you need to know and create deployments using both imperative and declarative approaches.

Prerequisites

  • 2 CPUs or more with 2GB of free memory

  • 20GB of free disk space

  • Docker or another compatible container runtime

Installing on Windows

To simplify the process, I suggest you to install Chocolatey Package Manager, then use following command:

choco install minikube

Basic Minikube Commands

1. Starting Minikube

minikube start --driver docker

This command initializes your local Kubernetes cluster. You can verify the status using:

minikube status

2. Managing the Cluster

Check cluster information:

kubectl cluster-info

View all nodes, pods and services in the cluster:

kubectl get nodes
kubectl get pod
kubectl get services

3. Creating Deployments

Method 1: Using Imperative Commands

Let's create a simple nginx deployment using the command line:

kubectl create deployment first-deploy --image=nginx:alpine
kubectl edit deployment first-deploy

This is how the configuration file that was created looks like:

Method 2: Using YAML (Declarative Approach)

Create a file named second-deploy.yaml:

type nul > second-deploy.yaml
notepad second-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80

Apply the configuration:

kubectl apply -f second-deploy.yaml

4. Accessing the Application

Create a service to expose the deployment:

kubectl expose deployment nginx-deployment --type=NodePort --port=80

Get the URL to access the service:

minikube service nginx-deployment --url

5. Monitoring Resources

View all resources:

kubectl get all

Check pod logs:

kubectl logs <pod-name>

6. Cleaning Up

Delete the deployments:

kubectl delete deployment first-deploy
kubectl delete deployment nginx-deployment

Stop Minikube:

minikube stop

Conclusion

These basic commands will help you get started with Minikube for local Kubernetes development. The combination of imperative commands and YAML configurations gives you flexibility in managing your deployments. As you become more comfortable with these basics, you can explore more advanced features like configuring persistent volumes, using ingress controllers, and managing multiple services.

Additional Tips

  • Use minikube dashboard to access the Kubernetes Dashboard UI

  • Execute minikube addons list to see available add-ons

  • Run kubectl describe pod <pod-name> for detailed pod information

  • Use kubectl exec -it <pod-name> --sh to get a shell inside a container

Remember to always clean up resources you're not using to free up system resources on your local machine.

Resources for Further Learning

1
Subscribe to my newsletter

Read articles from Georgiana Gorgan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Georgiana Gorgan
Georgiana Gorgan

Originally from Romania 🏑, I have decided to come to Germany in 2022. After a period of travelling, making friends and learning the language, I made the decision to stay here. Currently I am following my passion for IT and I am continuously specialising in Cloud Engineering and Artificial Intelligence.πŸ‘©πŸ»β€πŸ’» I completed a year-long training course here in Germany, where I learned about AWS, Doker, DevOps, Terraform, 🐧Linux, Python and other cloud services and tools. During this time, I also worked as a tutor for my colleagues, explaining cloud concepts and building cloud solutions together.