After learning the core concepts of Kubernetes, it’s time to dive deeper into the essentials that every beginner should master. This guide explains the next building blocks step by step.
1. Basic kubectl Commands
kubectl is the command-line tool used to interact with a Kubernetes cluster. Here are the most common commands:
-
Check cluster resources
kubectl get nodes kubectl get pods kubectl get services -
Get detailed info
kubectl describe pod <pod-name> -
Apply configuration
kubectl apply -f my-app.yaml -
Delete resources
kubectl delete pod <pod-name> kubectl delete -f my-app.yaml
These commands help you inspect, create, and manage resources in your cluster.
2. Writing Simple Deployment and Service YAMLs
Kubernetes resources are usually defined in YAML files.
-
Deployment Example
apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 3 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app image: nginx ports: - containerPort: 80 -
Service Example
apiVersion: v1 kind: Service metadata: name: my-app-service spec: type: LoadBalancer selector: app: my-app ports: - port: 80 targetPort: 80
The Deployment ensures your app runs with 3 replicas, while the Service exposes it so others can access it.
For a deeper dive into YAML files and manifests, take a look here.
3. Scaling Your Application
Scaling means changing the number of running pods.
-
Manual scaling:
kubectl scale deployment my-app --replicas=5 -
Automatic scaling (Horizontal Pod Autoscaler – HPA):
kubectl autoscale deployment my-app --min=2 --max=10 --cpu-percent=80
Kubernetes can adjust capacity automatically, so your app is always available and cost-efficient.
For more information regarding scaling, take a look here.
4. Monitoring and Logging Basics
To keep your apps healthy, you need visibility.
-
Logs (view what your app is doing):
kubectl logs <pod-name> -
Monitoring tools:
- Metrics Server (basic CPU/memory usage)
- Prometheus + Grafana (advanced monitoring & dashboards)
-
Health checks: Use liveness and readiness probes in your YAML to let Kubernetes know if your app is running correctly.
Example probe in a pod definition:
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 10
5. Putting It All Together
- Write YAML files for your Deployment and Service.
- Use
kubectl applyto create them. - Scale manually or automatically.
- Check logs and monitor performance.