Skip to main content

Kubernetes Documentation

What is Kubernetes? Imagine you have a Docker container running an app that can be accessed externally. If this app starts receiving a lot of traffic, a new container with the app needs to be spun up to distribute the traffic. This is where Kubernetes comes in as a container orchestration system. Think of Kubernetes as a conductor, controlling the flow and ensuring everything runs smoothly.

Kubernetes offers High Availability and Scalability , Portability and Popularity and Compatibility

Practical guide into Kubernetes

These commands correspond to each step in your practical guide to Kubernetes, covering cluster creation, application deployment, exploration, public exposure, scaling, and updating of your applications. Adjust the specific details like my-app-deployment.yaml, <pod-name>, and my-app:v2 to match your actual deployment and application needs.

🌐 Create a Kubernetes cluster

# Using Minikube for local development
minikube start

# Using Kubeadm (on-premises or cloud VM)
sudo kubeadm init

# Using Google Kubernetes Engine (GKE)
gcloud container clusters create my-cluster --zone us-central1-a

# Using Kind (Kubernetes IN Docker)
kind create cluster --name my-cluster

🚀 Deploy an app

kubectl apply -f my-app-deployment.yaml

witch shoul look like this

```yaml

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: my-app
image: nginx:latest
ports:
- containerPort: 80
```

🔍 Explore your app

kubectl get pods
kubectl describe pod <pod-name>

🌐 Expose your app publicly

kubectl expose deployment my-app --type=LoadBalancer --name=my-service

📈 Scale up your app

kubectl scale deployment my-app --replicas=5

🔄 Update your app

kubectl set image deployment/my-app my-app=my-app:v2

🚀 Level up Kubernetes

📦 Using Helm for Package Management

Helm is a package manager for Kubernetes that simplifies the deployment of applications and services.

🔄 Rolling Updates and Rollbacks

Kubernetes allows you to update your application seamlessly without downtime.

  • Perform a rolling update:

    kubectl set image deployment/my-app my-app=my-app:v2
  • Rollback an update:

    kubectl rollout undo deployment/my-app

🔒 Managing Secrets

Kubernetes provides a way to manage sensitive information such as passwords, OAuth tokens, and SSH keys.

  • Create a secret:

    kubectl create secret generic my-secret --from-literal=password=my-password
  • Use the secret in a pod:

    apiVersion: v1
    kind: Pod
    metadata:
    name: mypod
    spec:
    containers:
    - name: mycontainer
    image: nginx
    env:
    - name: SECRET_PASSWORD
    valueFrom:
    secretKeyRef:
    name: my-secret
    key: password

📊 Monitoring and Logging

Monitoring and logging are essential for maintaining the health and performance of your applications.

  • Install Prometheus for monitoring: helm install prometheus stable/prometheus

  • Install Grafana for visualization:

helm install grafana stable/grafana`
  • View logs for a pod: kubectl logs <pod-name>

🛡️ Network Policies

Network policies allow you to control the communication between different pods.

  • Create a network policy:
    apiVersion: networking.k8s.io/v1
    kind: NetworkPolicy
    metadata:
    name: allow-nginx
    spec:
    podSelector:
    matchLabels:
    app: nginx
    policyTypes:
    - Ingress
    ingress:
    - from:
    - podSelector:
    matchLabels:
    app: allowed-app