Background
Back to Blog

Getting Started with Kubernetes: A Beginner's Guide

Ankit Bhardwaj
KubernetesDevOpsTutorialBeginner

Getting Started with Kubernetes: A Beginner's Guide

Kubernetes has become the de facto standard for container orchestration. If you're new to Kubernetes, this guide will help you understand the core concepts and deploy your first application.

What is Kubernetes?

Kubernetes (K8s) is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Think of it as a conductor for your containers, ensuring they run smoothly across multiple machines.

Why Use Kubernetes?

  1. Automated Deployment: Deploy containers automatically across your cluster
  2. Scaling: Scale applications up or down based on demand
  3. Self-Healing: Automatically restart failed containers
  4. Load Balancing: Distribute traffic across multiple containers
  5. Rolling Updates: Update applications with zero downtime

Core Concepts

Pods

A Pod is the smallest deployable unit in Kubernetes. It contains one or more containers that share storage and network resources.

apiVersion: v1
kind: Pod
metadata:
  name: my-app
spec:
  containers:
  - name: nginx
    image: nginx:latest
    ports:
    - containerPort: 80

Deployments

Deployments manage the desired state of your application. They handle rolling updates and rollbacks.

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

Services

Services expose your Pods to network traffic, providing a stable endpoint even as Pods are created and destroyed.

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

Setting Up Your First Cluster

Using Minikube (Local Development)

# 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 installation
kubectl cluster-info
kubectl get nodes

Using Amazon EKS (Production)

# Install eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin

# Create cluster
eksctl create cluster \
  --name my-cluster \
  --region us-east-1 \
  --nodegroup-name standard-workers \
  --node-type t3.medium \
  --nodes 3

Deploying Your First Application

Step 1: Create a Deployment

Save this as deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: hello
  template:
    metadata:
      labels:
        app: hello
    spec:
      containers:
      - name: hello-app
        image: gcr.io/google-samples/hello-app:1.0
        ports:
        - containerPort: 8080

Apply the deployment:

kubectl apply -f deployment.yaml

Step 2: Expose Your Application

kubectl expose deployment hello-app \
  --type=LoadBalancer \
  --port=80 \
  --target-port=8080

Step 3: Verify Deployment

# Check pods
kubectl get pods

# Check service
kubectl get service hello-app

# View logs
kubectl logs <pod-name>

Essential kubectl Commands

# Get resources
kubectl get pods
kubectl get deployments
kubectl get services

# Describe resource
kubectl describe pod <pod-name>

# Execute command in pod
kubectl exec -it <pod-name> -- /bin/bash

# View logs
kubectl logs <pod-name>
kubectl logs -f <pod-name>  # Follow logs

# Scale deployment
kubectl scale deployment hello-app --replicas=5

# Delete resources
kubectl delete pod <pod-name>
kubectl delete deployment hello-app

Best Practices for Beginners

  1. Resource Limits: Always set resource requests and limits
  2. Health Checks: Implement liveness and readiness probes
  3. Labels: Use labels for organizing and selecting resources
  4. Namespaces: Use namespaces to separate environments
  5. ConfigMaps: Store configuration separately from code
  6. Secrets: Never hardcode sensitive information

Common Pitfalls to Avoid

  1. Running containers as root
  2. Not setting resource limits
  3. Storing state in containers
  4. Ignoring security best practices
  5. Not monitoring your cluster

Next Steps

After mastering the basics:

  1. Learn about StatefulSets for stateful applications
  2. Explore Helm for package management
  3. Implement CI/CD with Kubernetes
  4. Study network policies and security
  5. Learn about observability with Prometheus and Grafana

Need Kubernetes Training?

I offer hands-on Kubernetes workshops for individuals and teams. Whether you're just starting or looking to level up your skills, I can help. Contact me to discuss customized training.

Resources

AB

About the Author

Ankit Bhardwaj is a Site Reliability Engineer and Backend Developer with 10+ years of experience specializing in Kubernetes, AWS, Python automation, and DevOps practices. Based in Chandigarh, India.

Get in touch →