Kubernetes Basics: A Beginner’s Guide to Containers and Clusters

What is Kubernetes? Kubernetes is an open-source container orchestration platform used to deploy, scale, and manage containerized applications. This beginner-friendly Kubernetes guide explains the core concepts you need to understand before running applications in a Kubernetes cluster.

What Is Kubernetes?

Kubernetes, often abbreviated as K8s, automates the deployment and operation of containers across one or more machines. It helps keep applications available by scheduling workloads, restarting failed containers, distributing traffic, and scaling services as demand changes.

Why Use Kubernetes?

  • Automation: Kubernetes schedules workloads and can restart failed containers.
  • Scalability: Applications can be scaled up or down as traffic changes.
  • Service discovery: Built-in networking helps application components find one another.
  • Load balancing: Traffic can be distributed across healthy application instances.
  • Portability: Kubernetes concepts can be used across local servers, data centers, and cloud environments.

Core Kubernetes Concepts

Kubernetes Cluster

A Kubernetes cluster is a group of computers that runs Kubernetes. It contains a control plane and worker nodes.

Control Plane

The control plane manages the cluster. It stores configuration and state, makes scheduling decisions, and works to keep the actual environment aligned with the desired configuration. Key components include the API server, scheduler, controller manager, and a data store for cluster state.

Worker Nodes

Worker nodes are the machines that run application workloads. Each node typically includes a container runtime, the kubelet node agent, and networking components.

Pods

A Pod is the smallest deployable unit in Kubernetes. It contains one or more closely related containers that share networking and storage resources. Most applications use one main container per Pod.

Deployments

A Deployment describes how many replicas of an application should run and manages updates. For example, it can maintain three copies of a web application and perform a rolling update when a new version is released.

Services

Pods can be replaced and their network addresses may change. A Service provides a stable network endpoint and routes traffic to matching Pods. Common Service types include ClusterIP for internal access, NodePort for exposing a port on a node, and LoadBalancer when an external load balancer is available.

Namespaces

Namespaces logically separate resources inside a cluster. They are useful for organizing teams, environments, or projects and applying access and resource policies.

ConfigMaps and Secrets

ConfigMaps store non-sensitive configuration, while Secrets are intended for sensitive values such as passwords, tokens, and certificates. Access to Secrets should still be restricted.

How Kubernetes Works

Kubernetes uses a declarative model. You describe the desired state of an application in a YAML manifest, submit it to the Kubernetes API, and the control plane works continuously to make the cluster match that description.

  1. Describe the desired application state in a YAML manifest.
  2. Submit the configuration to the Kubernetes API.
  3. The control plane compares the desired state with the current state.
  4. The scheduler assigns Pods to suitable nodes.
  5. Kubernetes controllers keep the application aligned with the desired state.

Simple Kubernetes Deployment Example

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

This manifest asks Kubernetes to maintain two Pods running the specified container image. In production, use a deliberately selected image version instead of relying on a moving tag such as latest.

Useful kubectl Commands

kubectl is the command-line tool used to communicate with a Kubernetes cluster.

  • kubectl get nodes — list cluster nodes.
  • kubectl get pods — list Pods in the current namespace.
  • kubectl get deployments — view Deployments.
  • kubectl describe pod POD_NAME — inspect a Pod and its events.
  • kubectl logs POD_NAME — view container logs.
  • kubectl apply -f file.yaml — create or update resources from a manifest.

Kubernetes Best Practices for Beginners

  • Keep Kubernetes manifests in version control.
  • Set CPU and memory requests and limits for workloads.
  • Use readiness and liveness probes.
  • Apply least-privilege access with role-based access control.
  • Keep container images patched and pinned to known versions.
  • Separate development, staging, and production workloads.
  • Monitor logs, metrics, events, and resource usage.
  • Protect Secrets and never place credentials in source code.

Frequently Asked Questions About Kubernetes

Is Kubernetes a container?

No. A container packages an application and its dependencies, while Kubernetes manages containers across a cluster.

What is a Kubernetes Pod?

A Pod is Kubernetes’ smallest deployable unit and usually contains one main application container.

What is kubectl used for?

kubectl is used to view, deploy, inspect, and manage resources in a Kubernetes cluster.

Conclusion

Kubernetes provides a structured way to run containerized applications at scale. The most important Kubernetes basics are clusters, nodes, Pods, Deployments, Services, namespaces, and declarative manifests. Start with a small test cluster, deploy one service, and gradually explore networking, storage, security, and observability.

Leave a Reply

Your email address will not be published. Required fields are marked *

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top