🚀 How to Deploy a sampleapp on k3s using Ubuntu 24.04 (ProxmoxVE or EC2)

🚀 How to Deploy a sampleapp on k3s using Ubuntu 24.04 (ProxmoxVE  or EC2)

This step-by-step guide walks you through installing k3s on Ubuntu 24.04—either on a Linux Container (LXC) in Proxmox VE or on an EC2 instance—and deploying nginxusing a deploy.yaml file.


✅ Prerequisites

  • Ubuntu 24.04 LTS (LXC container on Proxmox or AWS EC2 instance)
  • Sudo access
  • Internet connectivity

🧱 Step 1: Update and Install Required Tools

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl

☸️ Step 2: Install k3s (Single-Node Kubernetes)

curl -sfL https://get.k3s.io | sh -

Verify installation

sudo k3s kubectl get nodes

🛠️ Step 3: Configure kubectl Access for Your User

mkdir -p $HOME/.kube
sudo cp /etc/rancher/k3s/k3s.yaml $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

#### Testing ;)
kubectl get nodes 

📄 Step 4: Create an nginx Deployment File

nano deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

🚀 Step 5: Deploy to k3s

kubectl apply -f deploy.yaml

🔍 Step 6: Check the Resources

kubectl get deployments,pods,services -A
kubectl get all

You should see:

  • A deployment named nginx-deployment
  • Two running pods
  • A service named nginx-service (type LoadBalancer)

⚠️ Optional: Change to NodePort (for local or Proxmox environments)

If you’re running k3s in a local container or Proxmox and LoadBalancer isn't supported, use this yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: NodePort

After running kubectl apply -f deploy.yaml run:

kubectl get svc

Look for a port in the range 30000–32767 to access nginx via your node IP.

For example, you should be able to run:

curl http://192.168.1.104:31722