
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.
To start Kubernetes via Minikube locally:
minikube start
To stop it:
minikube stop
Pods are ideal for:
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.
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 ConfigMaps and Secrets are used to provide configuration values and environment variables to your pods.
| Purpose | ConfigMap | Secrets |
|---|---|---|
| Data Type | Non-sensitive data | Sensitive data |
| Storage | Plain text (Base64 in etcd) | Base64-encoded, can be encrypted |
| Visibility | Easily viewable via kubectl | Access restricted via RBAC |
| Best Use | Hosts, ports, configs | Passwords, tokens, credentials |
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
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.
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
apiVersion: v1 kind: Service metadata:
name: example-service spec:
selector:
app: example-app
ports:
- protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30080
type: NodePort A Node is a physical or virtual machine that runs workloads inside Kubernetes. It hosts pods and includes:
In Minikube, running:
minikube start
creates a single-node cluster (one worker node).
View nodes:
kubectl get nodes
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" A Deployment manages pods for you by ensuring that the desired number of replicas are always running.
Benefits of using Deployments:
| Object | Represents |
|---|---|
| Pod | A single instance |
| Deployment | A manager that ensures the correct number of pods exist |
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>
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 Replicas are identical pod instances used for scaling and high availability.
They help:
If all replicas are overloaded, autoscaling can increase their number automatically.
Kubernetes Services automatically load-balance traffic across pod replicas.
The kube-proxy manages routing rules so traffic is distributed evenly.
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 Kubernetes supports three types of autoscaling:
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
Minikube provides a built-in dashboard:
minikube dashboard
This gives a visual overview of pods, nodes, deployments, services, and cluster activity.
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 ...