Getting Started with Kubernetes: A Developer's Guide

<h2>What is Kubernetes?</h2>

<p>Kubernetes (K8s) is an open-source container orchestration platform that automates deployment, scaling, and management of containerized applications. Originally developed by Google, it's now the industry standard for running containers at scale.</p>

<h2>Why Use Kubernetes?</h2>

<ul>

<li><strong>Auto-scaling:</strong> Automatically scale applications based on demand</li>

<li><strong>Self-healing:</strong> Restart failed containers, replace unhealthy nodes</li>

<li><strong>Load balancing:</strong> Distribute network traffic across containers</li>

<li><strong>Rolling updates:</strong> Deploy updates with zero downtime</li>

<li><strong>Service discovery:</strong> Containers find each other automatically</li>

</ul>

<h2>Core Concepts</h2>

<h3>Pod</h3>

<p>The smallest deployable unit in Kubernetes. A pod contains one or more containers that share storage and network.</p>

<pre><code>apiVersion: v1

kind: Pod

metadata:

  name: my-app

spec:

  containers:

  - name: app

    image: nginx:latest

    ports:

    - containerPort: 80</code></pre>

<h3>Deployment</h3>

<p>Manages a set of replica pods, ensuring the desired number always runs:</p>

<pre><code>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: app

        image: nginx:latest

        ports:

        - containerPort: 80</code></pre>

<h3>Service</h3>

<p>Exposes your application and provides stable networking:</p>

<pre><code>apiVersion: v1

kind: Service

metadata:

  name: my-app-service

spec:

  selector:

    app: my-app

  ports:

  - port: 80

    targetPort: 80

  type: LoadBalancer</code></pre>

<h2>Setting Up a Local Cluster</h2>

<p>Use <strong>minikube</strong> for local development:</p>

<pre><code># Install minikube

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

sudo install minikube-linux-amd64 /usr/local/bin/minikube

# Start cluster

minikube start

# Verify

kubectl get nodes</code></pre>

<h2>Deploying Your First App</h2>

<pre><code># Create deployment

kubectl create deployment hello-world --image=gcr.io/google-samples/hello-app:1.0

# Expose it

kubectl expose deployment hello-world --type=LoadBalancer --port=8080

# Check status

kubectl get pods

kubectl get services</code></pre>

<h2>Useful kubectl Commands</h2>

<ul>

<li><code>kubectl get pods</code> — List all pods</li>

<li><code>kubectl describe pod [name]</code> — Details about a pod</li>

<li><code>kubectl logs [pod-name]</code> — View pod logs</li>

<li><code>kubectl exec -it [pod] -- bash</code> — Shell into a pod</li>

<li><code>kubectl apply -f manifest.yaml</code> — Apply a configuration</li>

<li><code>kubectl delete -f manifest.yaml</code> — Delete resources</li>

</ul>

<h2>Conclusion</h2>

<p>Kubernetes has a steep learning curve, but it's the foundation of modern cloud-native development. Start with minikube locally, master the basics, then explore managed services like GKE, EKS, or AKS for production workloads.</p>