Urgent.News

600+ sources. One page. See who else covered it.

Editions

Tech

Kubernetes for Beginners: From Local to Production – May the Pods Be With You

The Quest Begins (The "Why") I remember the first time I tried to take a weekend side‑project from my laptop to something that felt “real”. I had a cute Express API that talked to Postman, a PostgreSQL container spun up with docker-compose up , and a React front‑end that lived in its own dev server. Everything worked beautifully … until I hit Ctrl+C on my laptop and the whole thing vanished. I…

The journey begins when a developer attempts to transition a simple weekend project from their laptop to a more robust, production-like environment. Early attempts with Docker Swarm and Nomad prove confusing, but a colleague introduces the concept of Kind clusters, which offer a locally hosted Kubernetes cluster for testing purposes.

This revelation feels like discovering a secret level in a classic arcade game, as it enables users to define their desired system state and let the cluster automatically manage the underlying infrastructure.

Kubernetes is fundamentally a declarative orchestrator. Developers specify the desired state of their application, such as the number of replicas, images to use, and exposed ports. Kubernetes then tirelessly works to maintain this state, automatically creating or restarting pods as needed. This process resembles the save game feature in RPGs, where players define the desired game state, and the engine handles loading, saving, and recovering from crashes.

Key components introduced early on include:

- **Pods**: The smallest deployable unit, which can contain one or more tightly coupled containers.

- **Deployments**: Manage sets of identical pods, handling updates and rollbacks.

- **Services**: Provide stable network endpoints to load balance traffic across multiple pods.

- **Ingress**: Optional feature that exposes HTTP/HTTPS routes from outside the cluster to services.

To get started, a simple Node.js API is used. The Dockerfile is straightforward, defining the base image, working directory, copying application files, and specifying the port and command to run. The image is built and pushed to a registry, such as Docker Hub.

A common mistake is using :latest in the Docker image tag, which can lead to version drift. It is recommended to pin a specific tag or use a digest. Additionally, setting resource limits (CPU, memory) and requests helps avoid resource starvation and ensures pods don’t consume excessive resources.

The manifest file, `hello-k8s.yaml`, defines a `Deployment` with two replicas, a `Service` for load balancing, and specifies resource limits to avoid overloading the node. Applying this manifest using `kubectl apply` reveals two running pods and the assigned cluster IP.

If a pod is intentionally deleted, Kubernetes quickly replaces it, demonstrating its self-healing capabilities. This behavior is crucial for maintaining high availability and reliability in production environments.

Key lessons and best practices include:

- Avoid using :latest in Docker images.

- Set resource limits for pods to prevent resource exhaustion.

- Ensure the `targetPort` in the Service matches the container’s listening port to avoid 502 errors.

- Utilize Kubernetes’ self-healing features like liveness and readiness probes.

The author concludes by inviting readers to experiment with a local Kind cluster, deploy the `hello-k8s` app, and expose it using the NGINX Ingress controller. This hands-on practice will solidify the understanding of Kubernetes concepts and demonstrate the power of self-healing and scalable deployments.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Discord Ticket Bot

A free, self-hosted ticket bot for Discord support teams. You run it yourself, so your ticket data never leaves your server.

  • Discord Ticket Bot is free and self-hosted
  • Up to 25 customizable ticket types available
  • Operates on SQLite or MySQL databases

Discord Giveaway Bot

A free, multilingual giveaway bot that keeps running through a restart. Entry with a single button click, customisable emoji, label and style Poll-based scheduler, so no giveaway is lost or orphaned…

  • Open-source, multilingual giveaway bot developed for Discord.
  • Allows custom emojis, labels, styles, and weighted bonus system.
  • Web-based dashboard for monitoring and managing public results.

More from Saturday 15 August →