K3S: Hands-On Projects

Deploy a Multi-Container Microservices App on K3s

Microservices are all the rage, so let’s deploy one in K3s. We’ll set up a frontend, backend, and database, because what’s a real-world app without a tangled web of dependencies?

Define Kubernetes Deployments, Services, and ConfigMaps

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: backend
  template:
    metadata:
      labels:
        app: backend
    spec:
      containers:
        - name: backend
          image: myrepo/backend:latest
          ports:
            - containerPort: 5000

Expose the Application via Ingress

After defining your deployments and services, expose the whole thing with Ingress so users can actually access it.

Set Up K3s HA Cluster with Ingress and Persistent Storage

If your cluster goes down, you’re in trouble. A High Availability (HA) setup prevents that.

Deploy a Multi-Master K3s Cluster

curl -sfL https://get.k3s.io | sh -s - server --cluster-init

Configure Worker Nodes to Join the HA Cluster

curl -sfL https://get.k3s.io | K3S_URL=https://<master-ip>:6443 K3S_TOKEN=<token> sh -

Set Up Ingress Using Traefik

Traefik is the default Ingress controller in K3s, making it easy to route traffic.

Deploy Applications with Persistent Storage

For persistent data, define a Persistent Volume (PV) and Persistent Volume Claim (PVC).

Implement GitOps using ArgoCD on K3s

Stop manually applying YAML files and embrace GitOps with ArgoCD.

Install ArgoCD

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Deploy an Application Using ArgoCD

argocd app create myapp --repo https://github.com/myrepo.git --path k8s-manifests --dest-server https://kubernetes.default.svc --dest-namespace default

Automate Deployments and Rollbacks

ArgoCD continuously syncs your cluster with Git, making deployments effortless and **rollbacks