3. Deploying Applications on Your K3s Cluster - Practical Examples


Once your K3s cluster is up and running, the next step is deploying applications. Whether you're experimenting with Kubernetes for the first time or testing production-ready workloads locally, K3s makes it simple and efficient. In this blog, we’ll walk through deploying a web application, adding a database service, and managing apps using Helm. By the end, you’ll have a solid understanding of deploying and monitoring applications on your K3s cluster.
Preparing Your Environment
Before we dive into deploying applications, let’s ensure your environment is ready:
Prerequisites
A functioning K3s cluster. (If you haven’t set one up yet, check out our guide on Getting Started with K3s.)
kubectl
installed and configured to communicate with your cluster.Basic familiarity with Kubernetes concepts (pods, deployments, services).
Optional: Install Helm (we’ll cover this later).
To verify your setup, run:
kubectl get nodes
You should see your K3s node(s) listed with a STATUS
of Ready
.
Example Deployments
Let’s start with a simple example: deploying a web application and a database service alongside it.
Deploying a Web Application
We’ll deploy a basic NGINX-based web app using a YAML manifest.
- Create a file named
web-app.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
labels:
app: web-app
spec:
replicas: 2
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web-app-service
spec:
selector:
app: web-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
- Apply the manifest:
kubectl apply -f web-app.yaml
- Verify the deployment:
kubectl get pods
You should see two pods running for the web-app
deployment.
- Access the app:
Find the external IP or port assigned to theweb-app-service
using:
kubectl get svc web-app-service
Access the web app in your browser or via curl
.
Adding a Database Service
Now, let’s add a database service (e.g., MySQL) to work alongside the web app.
- Create a file named
mysql.yaml
:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
env:
- name: MYSQL_ROOT_PASSWORD
value: rootpassword
ports:
- containerPort: 3306
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql-storage
volumes:
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-pvc
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
type: ClusterIP
- Apply the manifest:
kubectl apply -f mysql.yaml
- Verify the deployment:
kubectl get pods
Ensure the MySQL pod is running and its STATUS
is Running
.
Now your web app can connect to the MySQL service using the service name mysql
and port 3306
.
Using Helm Charts
K3s is fully compatible with Helm, a powerful Kubernetes package manager. Helm simplifies deploying and managing complex applications with reusable templates.
Installing Helm
- Download Helm:
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
- Verify installation:
helm version
Deploying Applications with Helm
Let’s use Helm to deploy WordPress (a web app + database combo).
- Add the Helm repo:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
- Install WordPress:
helm install my-wordpress bitnami/wordpress
- Check the status:
helm status my-wordpress
- Access the application:
Get the external IP of the WordPress service:
kubectl get svc
Visit the IP in your browser to see your WordPress site in action.
Monitoring and Managing Applications
Monitoring your applications is critical, even in a local environment. Here are a few tools and techniques for managing your K3s workloads:
Using kubectl
for Basic Monitoring
Check pod status:
kubectl get pods
View pod logs:
kubectl logs <pod-name>
Adding Metrics with Prometheus and Grafana
- Deploy Prometheus and Grafana using Helm:
helm install prometheus bitnami/kube-prometheus
helm install grafana bitnami/grafana
- Access the Grafana dashboard and connect it to Prometheus as a data source for visualizing metrics.
Conclusion
Deploying applications on K3s is not only straightforward but also versatile enough to handle a wide range of use cases. Whether you’re deploying simple web apps, integrating databases, or managing complex workloads with Helm, K3s provides the tools and simplicity to get the job done.
What’s Next?
Experiment with scaling your applications and using K3s in multi-node setups.
Explore CI/CD pipelines for automating application deployments on your K3s cluster.
Dive deeper into monitoring tools like Prometheus, Grafana, and Loki for a robust observability stack.
Have questions or cool deployment ideas? Let us know in the comments below!
Subscribe to my newsletter
Read articles from Suyash Bhawsar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Suyash Bhawsar
Suyash Bhawsar
Tech enthusiast, DevOps learner. Arch Linux w/ KDE. Rust learner. Harmonium player. Sudoku solver. Passionate about music and technology.