Tech News, Tech & Coding · Free Online Tools

IT Question Answer
Tools
Back to DevOps
Kubernetes Basics for Beginners

Kubernetes Basics for Beginners

DevOpsBy Muhammad Fareed
devopskubernetesbasicsbeginners

Short answer: Kubernetes (K8s) is an open-source system that runs and manages containers across many machines. You describe the state you want (for example, "run 3 copies of this app") and Kubernetes keeps the cluster in that state: restarting failed containers, spreading load and rolling out updates.

Why Kubernetes?

Running one container with Docker is easy. Running dozens across several servers is not: you need to place containers, restart crashed ones, scale up under load, update without downtime and let services find each other. Kubernetes automates all of that. If you are new to containers, read the Docker guide first.

Core building blocks

ObjectWhat it is
ClusterA set of machines running Kubernetes
NodeOne machine (physical or virtual) in the cluster
PodThe smallest unit: one or more containers that share network and storage
DeploymentManages a set of identical pods, handles updates and scaling
ServiceA stable address that load-balances traffic to pods
IngressRoutes outside HTTP(S) traffic to services
ConfigMap / SecretConfiguration and sensitive values kept outside the image
NamespaceA virtual partition of the cluster

Pods are temporary: they can be replaced at any time and get new IP addresses. That is why you use a Service instead of calling a pod directly.

A first Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:1.27
          ports:
            - containerPort: 80

Exposing it with a Service

apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  type: ClusterIP
  selector:
    app: web
  ports:
    - port: 80
      targetPort: 80

The Service finds pods by the label app: web and spreads requests among them. Use type LoadBalancer on a cloud provider, or an Ingress, to reach it from the internet.

Essential kubectl commands

kubectl apply -f deployment.yaml         # create or update from a file
kubectl get pods                         # list pods
kubectl get deployments,services         # list several resource types
kubectl describe pod <name>             # details and recent events
kubectl logs <pod-name>                  # view logs
kubectl exec -it <pod-name> -- sh        # open a shell
kubectl scale deployment web --replicas=5
kubectl rollout status deployment web
kubectl rollout undo deployment web      # roll back a bad update
kubectl delete -f deployment.yaml

Key features in action

  • Self-healing: if a pod crashes or a node fails, Kubernetes starts a replacement.
  • Scaling: change replicas, or use a Horizontal Pod Autoscaler to scale on CPU or other metrics.
  • Rolling updates: new versions replace old pods gradually, so the app stays available.
  • Service discovery: pods find services by DNS name.
  • Health checks: liveness and readiness probes tell Kubernetes when to restart or send traffic.

Trying Kubernetes locally

You do not need a cloud account to learn. Tools such as minikube, kind or the Kubernetes option in Docker Desktop create a small local cluster. Managed services like Amazon EKS, Google GKE and Azure AKS run the control plane for you in production; see AWS basics to understand the cloud side.

Do you really need Kubernetes?

Kubernetes is powerful but adds complexity. For a single small app, a managed platform or plain Docker Compose may be simpler and cheaper. Consider Kubernetes when you run many services, need automated scaling and rollouts, or must run across multiple servers or clouds.

Next steps

Automate delivery with a CI/CD pipeline, manage infrastructure as code with Terraform, and see the big picture in what is DevOps.

FAQs

Is Kubernetes the same as Docker?

No. Docker builds and runs containers. Kubernetes orchestrates many containers across machines. Kubernetes can run containers built with Docker.

What does K8s mean?

It is shorthand for Kubernetes: K, then 8 letters, then s.

What is the difference between a pod and a container?

A pod wraps one or more containers and gives them shared networking and storage. Most pods contain one main container.

Is Kubernetes free?

The software is open source. You pay for the servers or the managed service that runs it.