Kubernetes Basics: A Beginner’s Guide to Kubectl on Minikube

Kubernetes Basics: A Beginner’s Guide to Kubectl on Minikube

Science and Technology
Personal Development
By Beatrice MarroPublished on December 2, 2025
#kubernetes
#K8s
#DevOps
#CloudNative
#Containers
#CloudComputing
#LearnKubernetes
#DevOpsForBeginners
#TechTutorial
#CloudLearning
#DeveloperTips
#Minikube

Introduction

Kubernetes is an open-source platform that automates the deployment, scaling, and management of containerized applications, helping teams run complex systems reliably and efficiently. It ensures applications are highly available, scalable, and self-healing. Kubectl is the command-line tool used to interact with Kubernetes clusters—allowing you to deploy resources, inspect their status, and manage cluster operations.

In this blog, we use kubectl with Minikube, a lightweight local Kubernetes environment ideal for learning, experimenting, and testing Kubernetes components.


1. Starting and Stopping

To start Kubernetes via Minikube locally:

minikube start 

To stop it:

minikube stop


2. Pods

Definition

  • A Pod is the smallest deployable unit in Kubernetes and can contain one or more containers.
  • A manifest file (YAML) is required to define and create a pod.
  • Pods are ephemeral by nature: they are created, destroyed, and replaced over time.

Pods are ideal for:

  • Simple testing
  • One-time debugging
  • Learning Kubernetes basics

Commands

Create or update a pod using its manifest:

kubectl apply -f pod.yaml

Delete a specific pod:

kubectl delete pod <pod-name>

Delete all pods:

kubectl delete pods --all 

Get all pods:

kubectl get pods

Check logs of a pod:

kubectl logs <pod-name>

Port-forward a pod (useful for local debugging):

kubectl port-forward pod/<pod-name> 8082:8082

This exposes the pod’s port to your local machine at port 8082.

Example Manifest (Generic)

apiVersion: v1 kind: Pod metadata:
  name: example-pod
  labels:
    app: example-app spec:
  containers:
    - name: example-container
      image: your-docker-image:latest
      ports:
        - containerPort: 8080
      envFrom:
        - configMapRef:
            name: example-config
        - secretRef:
            name: example-secret
  imagePullSecrets:
    - name: regcred 

3. ConfigMaps and Secrets

Definition

ConfigMaps and Secrets are used to provide configuration values and environment variables to your pods.

  • ConfigMaps store non-sensitive configuration data.
  • Secrets store sensitive data such as passwords, API keys, and tokens.

Differences

PurposeConfigMapSecrets
Data TypeNon-sensitive dataSensitive data
StoragePlain text (Base64 in etcd)Base64-encoded, can be encrypted
VisibilityEasily viewable via kubectlAccess restricted via RBAC
Best UseHosts, ports, configsPasswords, tokens, credentials

Examples (Generic)

ConfigMap:

apiVersion: v1 kind: ConfigMap metadata:
  name: example-config data:
  DB_HOST: "database.server.local"
  DB_PORT: "1433"
  FEATURE_FLAG: "true" 

Secret:

apiVersion: v1 kind: Secret metadata:
  name: example-secret type: Opaque stringData:
  DB_PASSWORD: "your-db-password"
  API_KEY: "your-api-key" 

Apply changes:

kubectl apply -f configmap.yaml kubectl apply -f secrets.yaml


4. Services

Definition

A Service is a stable networking abstraction that provides reliable access to a set of pods. Even when pods restart or get replaced, the service remains constant.

Services use selectors to route traffic to matching pods based on their labels.

Commands

List services:

kubectl get services

Describe a service:

kubectl describe service <service-name>

Check the endpoints associated with a service:

kubectl get endpoints <service-name>

Create or update a service:

kubectl apply -f service.yaml

Delete a service:

kubectl delete service <service-name>

Run a service locally (Minikube):

minikube service <service-name>

Port-forward a service:

kubectl port-forward service/<service-name> <port>:<port> -n default

Example Manifest (Generic)

apiVersion: v1 kind: Service metadata:
  name: example-service spec:
  selector:
    app: example-app
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30080
  type: NodePort 

5. Nodes

A Node is a physical or virtual machine that runs workloads inside Kubernetes. It hosts pods and includes:

  • A container runtime (e.g., Docker or containerd)
  • The kubelet agent
  • A network proxy
  • System components needed to run containers

In Minikube, running:

minikube start 

creates a single-node cluster (one worker node).

View nodes:

kubectl get nodes


6. Setting Resources and Limits

Requests define the minimum resources a container needs.
Limits define the maximum resources a container is allowed to consume.

Example snippet:

resources:
  requests:
    memory: "64Mi"
    cpu: "50m"
  limits:
    memory: "128Mi"
    cpu: "100m" 

7. Deployments

A Deployment manages pods for you by ensuring that the desired number of replicas are always running.

Benefits of using Deployments:

  • Automatic restarts
  • Easy scaling
  • Rolling updates (zero-downtime)
  • Self-healing pods

Key Differences

ObjectRepresents
PodA single instance
DeploymentA manager that ensures the correct number of pods exist

Commands

Apply a deployment:

kubectl apply -f deployment.yaml

List deployments:

kubectl get deployments

Scale a deployment:

kubectl scale deployment <name> --replicas=<number>

Check rollout status:

kubectl rollout status deployment <name>

Describe a deployment:

kubectl describe deployment <name>

Example (Generic)

apiVersion: apps/v1 kind: Deployment metadata:
  name: example-deployment spec:
  replicas: 2
  selector:
    matchLabels:
      app: example-app
  template:
    metadata:
      labels:
        app: example-app
    spec:
      containers:
        - name: example-container
          image: your-docker-image:latest
          resources:
            requests:
              memory: "64Mi"
              cpu: "50m"
            limits:
              memory: "128Mi"
              cpu: "100m"
          ports:
            - containerPort: 8080
          envFrom:
            - configMapRef:
                name: example-config
            - secretRef:
                name: example-secret
      imagePullSecrets:
        - name: regcred 

8. Replicas

Replicas are identical pod instances used for scaling and high availability.

They help:

  1. Handle more traffic
  2. Ensure high availability
  3. Distribute load evenly

If all replicas are overloaded, autoscaling can increase their number automatically.


9. Load Balancing

Kubernetes Services automatically load-balance traffic across pod replicas.
The kube-proxy manages routing rules so traffic is distributed evenly.

Ingress Controllers

An NGINX Ingress Controller provides centralized routing for external HTTP/S access.

Useful commands:

kubectl get pods -n ingress-nginx kubectl get services -n ingress-nginx kubectl describe ingress <ingress-name> kubectl port-forward -n ingress-nginx service/ingress-nginx-controller 8000:80 

Example Ingress:

apiVersion: networking.k8s.io/v1 kind: Ingress metadata:
  name: example-ingress spec:
  rules:
    - host: localhost
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: example-service
                port:
                  number: 8080 

10. Autoscaling

Kubernetes supports three types of autoscaling:

  1. HPA (Horizontal Pod Autoscaler) — adjusts the number of replicas
  2. VPA (Vertical Pod Autoscaler) — adjusts resource limits/requests
  3. Cluster Autoscaler — adjusts number of nodes (not available in Minikube)

Example HPA Manifest

apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata:
  name: example-hpa spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: example-deployment
  minReplicas: 1
  maxReplicas: 3
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70 

Apply it:

kubectl apply -f example-hpa.yaml

Other commands:

kubectl get hpa kubectl describe hpa <name> kubectl delete hpa <name> kubectl top nodes


11. Monitoring the Kubernetes Cluster

Minikube provides a built-in dashboard:

minikube dashboard

This gives a visual overview of pods, nodes, deployments, services, and cluster activity.

Created by:
B
Beatrice Marro

I am a passionate ICT student at Fontys University of Applied Sciences specializing in Software Engineering and Artificial Intelligence, with experience in impactful real-world projects including an internship at Philips where I developed an AI solution that automated packaging verification and was implemented company-wide. Beyond this, I have contributed to diverse projects such as building human-bot communities, creating an office meetup app with Ordina, and developing a real-time AI ear tag ...