Kubernetes homelab with k3s, Traefik and n8n
- #Kubernetes
- #Homelab
- #DevOps

Introduction
This is how I set up a small Kubernetes cluster at home on Rocky Linux 10.1, with n8n as the first application.
Not everything worked the first time, so I wrote down the errors I ran into and how I fixed them.
What you get
- k3s: a lightweight Kubernetes distribution
- Traefik: reverse proxy and ingress controller
- Cert-Manager: Let’s Encrypt certificates via Cloudflare DNS challenge
- Sealed Secrets: encrypted secrets you can commit to Git
- Prometheus & Grafana: monitoring with dashboards
- n8n + PostgreSQL: workflow automation with its own database
- Local storage: all data stays on the local disk
All services are available over HTTPS with valid certificates.
Why these tools?
- k3s needs less than 512 MB of RAM and runs fine on a single node
- Traefik works well with Kubernetes
- Sealed Secrets lets me keep secrets in Git
- Local storage doesn’t depend on anything outside my hardware
Prerequisites
You need:
- A server or VM running Rocky Linux 10.1 Minimal (4GB RAM minimum, 8GB recommended)
- A domain name managed by Cloudflare
- Cloudflare API token with DNS edit permissions
- Root or sudo access to your server
- Some experience with the command line and Kubernetes
Getting Your Cloudflare API Token
- Log into Cloudflare Dashboard
- Go to My Profile → API Tokens
- Click Create Token
- Use the Edit zone DNS template
- Set Zone Resources to include your specific domain
- Create token and save it securely
Make sure the token is for the right domain. I got that wrong, more on that below.
Phase 1: System Preparation
First, install the tools we need on Rocky Linux.
# Update system
sudo dnf update -y
# Install essential tools
sudo dnf install -y \
tar \
openssl \
wget \
curl \
git \
vim \
htop \
bind-utils \
net-tools \
httpd-tools
# Configure firewall
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --permanent --add-port=6443/tcp
sudo firewall-cmd --reload
What they are for:
tarandopenssl: Required for Helm installationbind-utils: DNS troubleshootinghttpd-tools: For creating BasicAuth passwords- Firewall ports: HTTP (80), HTTPS (443), and Kubernetes API (6443)
Troubleshooting: Missing Dependencies
Rocky Linux 10.1 Minimal really is minimal. Without these tools you get errors like:
[ERROR] Could not find tar. It is required to extract the helm binary archive.
Install them all at once. Otherwise you end up installing them one by one.
Phase 2: Installing k3s
k3s is a certified Kubernetes distribution made for small machines, so it suits a homelab.
# Install k3s without built-in Traefik (we'll install our own)
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--disable traefik" sh -
# Set up kubectl access for your user
mkdir -p ~/.kube
sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
sudo chown $(id -u):$(id -g) ~/.kube/config
chmod 600 ~/.kube/config
# Configure kubectl to use your config
echo 'export KUBECONFIG=~/.kube/config' >> ~/.bashrc
source ~/.bashrc
# Verify installation
kubectl get nodes
The node should show “Ready”. k3s also comes with a local-path storage provisioner, so volumes are created automatically.
Troubleshooting: kubectl Permission Denied
After the installation you might see:
$ kubectl get pods
WARN[0000] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode
error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied
kubectl is trying to read the k3s config that belongs to root, not your own copy.
Point KUBECONFIG to your copy:
# Add to .bashrc for persistence
echo 'export KUBECONFIG=~/.kube/config' >> ~/.bashrc
source ~/.bashrc
# Test
kubectl get nodes
kubectl now always uses the config you have permissions for.
Fix the networking on Rocky Linux 10
Don’t skip this one. Rocky Linux 10 uses nftables by default, but Flannel in k3s runs in iptables mode. Pods can’t reach each other, and Traefik answers with 502 Bad Gateway.
You can tell by this:
- Traefik shows
502 Bad Gatewaywhen accessing services - Direct pod IP connections fail with “Host is unreachable”
- Services work via DNS but not via pod IPs
Set k3s to iptables mode explicitly:
# Stop k3s
sudo systemctl stop k3s
# Edit k3s service file
sudo cat > /etc/systemd/system/k3s.service <<'EOF'
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
Wants=network-online.target
After=network-online.target
[Install]
WantedBy=multi-user.target
[Service]
Type=notify
EnvironmentFile=-/etc/default/%N
EnvironmentFile=-/etc/sysconfig/%N
EnvironmentFile=-/etc/systemd/system/k3s.service.env
KillMode=process
Delegate=yes
User=root
LimitNOFILE=1048576
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
TimeoutStartSec=0
Restart=always
RestartSec=5s
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s \
server \
'--disable' \
'traefik' \
'--kube-proxy-arg' \
'proxy-mode=iptables'
EOF
# Reload and start
sudo systemctl daemon-reload
sudo systemctl start k3s
# Wait 45 seconds for initialization
sleep 45
# Verify pod-to-pod connectivity works
kubectl get pods -A
kube-proxy now uses iptables mode, which works with Flannel.
Test it:
# Get two pod IPs from different namespaces
TRAEFIK_IP=$(kubectl get pod -n kube-system -l app.kubernetes.io/name=traefik -o jsonpath='{.items[0].status.podIP}' 2>/dev/null || echo "not-yet-installed")
TEST_POD_IP=$(kubectl get pod -n kube-system -l k8s-app=kube-dns -o jsonpath='{.items[0].status.podIP}')
echo "If these commands work, networking is fixed!"
echo "Test Pod IP: $TEST_POD_IP"
# This should succeed
kubectl run test-pod --image=busybox:latest --restart=Never -it --rm -- wget -O- http://$TEST_POD_IP:8080/health --timeout=5
Any answer is fine, even a 404 or “connection refused”. Only “Host is unreachable” means it still doesn’t work.
Phase 3: Installing Helm
Helm is the package manager for Kubernetes. We need it for Traefik and Prometheus.
# Install Helm manually (more reliable on minimal systems)
cd /tmp
curl -LO https://get.helm.sh/helm-v3.14.0-linux-amd64.tar.gz
tar -zxvf helm-v3.14.0-linux-amd64.tar.gz
sudo mv linux-amd64/helm /usr/local/bin/helm
sudo chmod +x /usr/local/bin/helm
# Clean up
rm -rf /tmp/helm-* /tmp/linux-amd64
# Add Helm repositories
helm repo add traefik https://traefik.github.io/charts
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
# Verify
helm version
I install it manually because the Helm script needs openssl and tar and fails silently without them.
Phase 4: Sealed Secrets
How do you keep Kubernetes secrets in Git without exposing them? With Sealed Secrets, you only commit the encrypted version.
How Sealed Secrets Work
- You create a normal Kubernetes Secret locally
- Use
kubesealto encrypt it with your cluster's public key - The encrypted SealedSecret can safely be committed to Git
- Only your cluster can decrypt it using its private key
# Install Sealed Secrets controller
kubectl apply -f https://github.com/bitnami-labs/sealed-secrets/releases/download/v0.26.0/controller.yaml
# Wait for it to be ready
kubectl wait --for=condition=Available --timeout=300s -n kube-system deployment/sealed-secrets-controller
# Install kubeseal CLI
cd /tmp
wget https://github.com/bitnami-labs/sealed-secrets/releases/download/v0.26.0/kubeseal-0.26.0-linux-amd64.tar.gz
tar -xvzf kubeseal-0.26.0-linux-amd64.tar.gz
sudo install -m 755 kubeseal /usr/local/bin/kubeseal
# Clean up
rm -f /tmp/kubeseal*
# Verify
kubeseal --version
Back up your master key
# Export the master key - you'll need this for disaster recovery
kubectl get secret -n kube-system -l sealedsecrets.bitnami.com/sealed-secrets-key \
-o yaml > ~/sealed-secrets-master-key-backup.yaml
echo "⚠️ Store this file securely - without it, you can't decrypt your secrets!"
Keep this key in a password manager or an encrypted backup. If you lose the cluster and the key, you can’t decrypt your secrets any more.
Phase 5: Creating the Project Structure
This is how I organise the files:
# Create project directory
mkdir -p ~/k8s && cd ~/k8s
# Create organized structure
mkdir -p base/clusterissuers
mkdir -p infrastructure/cert-manager/secrets
mkdir -p infrastructure/traefik/middleware
mkdir -p infrastructure/monitoring/{secrets,servicemonitors}
mkdir -p apps/n8n/{postgres,n8n,ingress}
mkdir -p scripts
mkdir -p secrets
# Create .gitignore
cat > .gitignore <<'EOF'
# Plaintext secrets - NEVER commit these!
secrets/
!secrets/.gitkeep
# Temporary files
*.tmp
*.bak
pub-cert.pem
# Environment files
.env
.env.*
EOF
# Fetch the public certificate for kubeseal
kubeseal \
--controller-name=sealed-secrets-controller \
--controller-namespace=kube-system \
--fetch-cert > pub-cert.pem
What goes where:
base/: Cluster-wide resources (namespaces, issuers)infrastructure/: Core services that other apps depend onapps/: Your applications, each in its own directorysecrets/: ignored by Git, plaintext secrets live here temporarily
Phase 6: Setting Up Namespaces and Cert-Manager
Create Namespaces
cat > base/namespaces.yaml <<'EOF'
apiVersion: v1
kind: Namespace
metadata:
name: infrastructure
labels:
name: infrastructure
---
apiVersion: v1
kind: Namespace
metadata:
name: n8n
labels:
name: n8n
EOF
kubectl apply -f base/namespaces.yaml
Install Cert-Manager
Cert-Manager requests the Let’s Encrypt certificates and renews them.
# Install Cert-Manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.0/cert-manager.yaml
# Wait for it to be ready (takes 1-2 minutes)
kubectl wait --for=condition=Available --timeout=300s -n cert-manager deployment/cert-manager
# Verify
kubectl get pods -n cert-manager
Create Cloudflare API Token Secret
Now the first encrypted secret. Replace YOUR_CLOUDFLARE_API_TOKEN with your token.
# Create plaintext secret (locally only)
cat > secrets/cloudflare-api-token.yaml <<'EOF'
apiVersion: v1
kind: Secret
metadata:
name: cloudflare-api-token
namespace: cert-manager
type: Opaque
stringData:
api-token: "YOUR_CLOUDFLARE_API_TOKEN"
EOF
# Encrypt it with kubeseal
kubeseal --format yaml --cert pub-cert.pem \
< secrets/cloudflare-api-token.yaml \
> base/clusterissuers/cloudflare-api-token.enc.yaml
# Delete plaintext version
rm secrets/cloudflare-api-token.yaml
# Deploy the encrypted secret
kubectl apply -f base/clusterissuers/cloudflare-api-token.enc.yaml
# Verify (you'll see the decrypted Secret, not the SealedSecret)
kubectl get secret -n cert-manager cloudflare-api-token
What happened here:
- We created a normal Secret with our API token
kubesealencrypted it using the cluster's public key- The encrypted version (
.enc.yaml) is safe to commit to Git - When applied, the Sealed Secrets controller automatically decrypts it
The secret has to be in the cert-manager namespace, because that’s where ClusterIssuers look by default. It’s easy to miss.
Create Let’s Encrypt ClusterIssuers
Replace your-email@example.com with your email address and example.com with your domain.
cat > base/clusterissuers/letsencrypt-cloudflare.yaml <<'EOF'
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: your-email@example.com
privateKeySecretRef:
name: letsencrypt-prod
solvers:
- dns01:
cloudflare:
apiTokenSecretRef:
name: cloudflare-api-token
key: api-token
selector:
dnsZones:
- "example.com"
---
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-staging
spec:
acme:
server: https://acme-staging-v02.api.letsencrypt.org/directory
email: your-email@example.com
privateKeySecretRef:
name: letsencrypt-staging
solvers:
- dns01:
cloudflare:
apiTokenSecretRef:
name: cloudflare-api-token
key: api-token
selector:
dnsZones:
- "example.com"
EOF
kubectl apply -f base/clusterissuers/letsencrypt-cloudflare.yaml
Why two issuers?
- staging is for testing and has higher rate limits
- prod has strict limits (5 certificates per week per domain)
Test with staging first.
Phase 7: Deploying Traefik
Traefik is the ingress controller. It routes traffic from outside to the services and handles TLS.
Create Traefik Configuration
cat > infrastructure/traefik/helm-values.yaml <<'EOF'
deployment:
kind: Deployment
replicas: 1
ports:
web:
port: 80
exposedPort: 80
websecure:
port: 443
exposedPort: 443
metrics:
port: 9100
exposedPort: 9100
service:
type: LoadBalancer
ingressRoute:
dashboard:
enabled: false
logs:
general:
level: INFO
access:
enabled: true
# Prometheus Metrics
metrics:
prometheus:
enabled: true
entryPoint: metrics
addEntryPointsLabels: true
addRoutersLabels: true
addServicesLabels: true
additionalArguments:
- "--metrics.prometheus=true"
EOF
Install Traefik
helm install traefik traefik/traefik \
--namespace infrastructure \
--values infrastructure/traefik/helm-values.yaml \
--wait
# Verify
kubectl get pods -n infrastructure -l app.kubernetes.io/name=traefik
kubectl get svc -n infrastructure traefik
Troubleshooting: Traefik Helm Values Error
You might get this error during the installation:
Error: INSTALLATION FAILED: values don't meet the specifications of the schema(s)
- at '/ports/metrics/expose': got boolean, want object
Older instructions use expose: true for the metrics port. Newer Traefik charts expect something else.
Remove the expose: true line from the metrics port. metrics.prometheus.enabled: true takes care of it.
Create Useful Middlewares
cat > infrastructure/traefik/middleware/redirect-https.yaml <<'EOF'
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: redirect-https
namespace: infrastructure
spec:
redirectScheme:
scheme: https
permanent: true
---
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: security-headers
namespace: infrastructure
spec:
headers:
frameDeny: true
browserXssFilter: true
contentTypeNosniff: true
stsIncludeSubdomains: true
stsPreload: true
stsSeconds: 31536000
EOF
kubectl apply -f infrastructure/traefik/middleware/
Phase 8: Deploying Prometheus and Grafana
Next, monitoring. The kube-prometheus-stack has everything we need.
Create Grafana Admin Secret
# Generate a secure password
GRAFANA_PASSWORD=$(openssl rand -base64 32)
echo "Grafana password: $GRAFANA_PASSWORD"
echo "⚠️ Save this password!"
# Create and encrypt secret
cat > secrets/grafana-admin.yaml <<EOF
apiVersion: v1
kind: Secret
metadata:
name: grafana-admin-secret
namespace: infrastructure
type: Opaque
stringData:
admin-user: "admin"
admin-password: "$GRAFANA_PASSWORD"
EOF
kubeseal --format yaml --cert pub-cert.pem \
< secrets/grafana-admin.yaml \
> infrastructure/monitoring/secrets/grafana-admin.enc.yaml
rm secrets/grafana-admin.yaml
kubectl apply -f infrastructure/monitoring/secrets/grafana-admin.enc.yaml
The Grafana chart needs both admin-user and admin-password in the secret.
Create Prometheus BasicAuth Secret
# Create password
read -sp "Enter Prometheus password: " PROM_PASS
echo
PROM_HASH=$(htpasswd -nb admin "$PROM_PASS")
# Create and encrypt secret
cat > secrets/prometheus-auth.yaml <<EOF
apiVersion: v1
kind: Secret
metadata:
name: prometheus-auth
namespace: infrastructure
type: Opaque
stringData:
users: |
$PROM_HASH
EOF
kubeseal --format yaml --cert pub-cert.pem \
< secrets/prometheus-auth.yaml \
> infrastructure/monitoring/secrets/prometheus-auth.enc.yaml
rm secrets/prometheus-auth.yaml
kubectl apply -f infrastructure/monitoring/secrets/prometheus-auth.enc.yaml
Create Monitoring Helm Values
Replace grafana.example.com with your actual domain.
cat > infrastructure/monitoring/helm-values.yaml <<'EOF'
prometheus:
prometheusSpec:
retention: 15d
storageSpec:
volumeClaimTemplate:
spec:
storageClassName: local-path
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 20Gi
resources:
requests:
cpu: 200m
memory: 512Mi
limits:
cpu: 1000m
memory: 2Gi
grafana:
enabled: true
admin:
existingSecret: grafana-admin-secret
userKey: admin-user
passwordKey: admin-password
persistence:
enabled: true
storageClassName: local-path
size: 5Gi
grafana.ini:
server:
root_url: "https://grafana.example.com"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
alertmanager:
alertmanagerSpec:
storage:
volumeClaimTemplate:
spec:
storageClassName: local-path
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
nodeExporter:
enabled: true
kubeStateMetrics:
enabled: true
EOF
Install Monitoring Stack
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
--namespace infrastructure \
--values infrastructure/monitoring/helm-values.yaml \
--wait
# This takes 2-3 minutes
kubectl get pods -n infrastructure | grep -E "(prometheus|grafana|alertmanager)"
Create Certificates for Monitoring
Replace example.com with your domain.
cat > infrastructure/monitoring/certificates.yaml <<'EOF'
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: grafana-tls
namespace: infrastructure
spec:
secretName: grafana-tls-secret
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer
dnsNames:
- grafana.example.com
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: prometheus-tls
namespace: infrastructure
spec:
secretName: prometheus-tls-secret
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer
dnsNames:
- prometheus.example.com
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: alertmanager-tls
namespace: infrastructure
spec:
secretName: alertmanager-tls-secret
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer
dnsNames:
- alertmanager.example.com
EOF
kubectl apply -f infrastructure/monitoring/certificates.yaml
# Watch certificate status
kubectl get certificate -n infrastructure -w
Create IngressRoutes for Monitoring
Replace example.com with your domain.
cat > infrastructure/monitoring/ingressroutes.yaml <<'EOF'
# Grafana
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: grafana-https
namespace: infrastructure
spec:
entryPoints:
- websecure
routes:
- match: Host(`grafana.example.com`)
kind: Rule
services:
- name: kube-prometheus-stack-grafana
port: 80
tls:
secretName: grafana-tls-secret
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: grafana-http
namespace: infrastructure
spec:
entryPoints:
- web
routes:
- match: Host(`grafana.example.com`)
kind: Rule
middlewares:
- name: redirect-https
services:
- name: kube-prometheus-stack-grafana
port: 80
---
# Prometheus
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: prometheus-auth
namespace: infrastructure
spec:
basicAuth:
secret: prometheus-auth
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: prometheus-https
namespace: infrastructure
spec:
entryPoints:
- websecure
routes:
- match: Host(`prometheus.example.com`)
kind: Rule
middlewares:
- name: prometheus-auth
services:
- name: kube-prometheus-stack-prometheus
port: 9090
tls:
secretName: prometheus-tls-secret
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: prometheus-http
namespace: infrastructure
spec:
entryPoints:
- web
routes:
- match: Host(`prometheus.example.com`)
kind: Rule
middlewares:
- name: redirect-https
services:
- name: kube-prometheus-stack-prometheus
port: 9090
---
# AlertManager
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: alertmanager-https
namespace: infrastructure
spec:
entryPoints:
- websecure
routes:
- match: Host(`alertmanager.example.com`)
kind: Rule
middlewares:
- name: prometheus-auth
services:
- name: kube-prometheus-stack-alertmanager
port: 9093
tls:
secretName: alertmanager-tls-secret
---
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: alertmanager-http
namespace: infrastructure
spec:
entryPoints:
- web
routes:
- match: Host(`alertmanager.example.com`)
kind: Rule
middlewares:
- name: redirect-https
services:
- name: kube-prometheus-stack-alertmanager
port: 9093
EOF
kubectl apply -f infrastructure/monitoring/ingressroutes.yaml
Configure DNS in Cloudflare
Add these A records in your Cloudflare dashboard:
A grafana.example.com → YOUR_SERVER_IP
A prometheus.example.com → YOUR_SERVER_IP
A alertmanager.example.com → YOUR_SERVER_IP
It takes 2–3 minutes until the certificates are issued.
Troubleshooting: Certificates Stay in “Ready: False” State
This happened to me too. Here is how I tracked it down.
The certificates show Ready: False for more than 5 minutes:
$ kubectl get certificate -n infrastructure
NAME READY SECRET AGE
grafana-tls False grafana-tls-secret 20m
prometheus-tls False prometheus-tls-secret 20m
Step 1: Check Certificate Details
kubectl describe certificate grafana-tls -n infrastructure
Look at the events at the bottom:
- “Issuing certificate as Secret does not exist”: normal, wait a bit
- “Waiting for DNS propagation”: the DNS challenge is running
- “Error getting cloudflare secret: secrets not found”: that’s the problem
Step 2: Verify the Secret Exists and is in the Right Place
# Check if SealedSecret was created
kubectl get sealedsecret -n cert-manager
# Check if the actual Secret was created
kubectl get secret cloudflare-api-token -n cert-manager
Often the secret is in the wrong namespace.
Many tutorials (and my first attempt) put the Cloudflare secret in the infrastructure namespace, but ClusterIssuers look in cert-manager by default.
To fix it:
# If secret is in wrong namespace, copy it to cert-manager
kubectl get secret cloudflare-api-token -n infrastructure -o yaml | \
sed 's/namespace: infrastructure/namespace: cert-manager/' | \
kubectl apply -f -
# Verify
kubectl get secret cloudflare-api-token -n cert-manager
Step 3: Check Sealed Secrets Controller
# Is controller running?
kubectl get pods -n kube-system | grep sealed-secrets
# Check controller logs
kubectl logs -n kube-system -l name=sealed-secrets-controller --tail=50
Look for messages like:
- “SealedSecret unsealed successfully”: good
- “Decryption errors”: the secret was encrypted with the wrong key
Step 4: Verify Cert-Manager Can Access the Secret
# Check cert-manager logs
kubectl logs -n cert-manager deployment/cert-manager --tail=100
# Look for errors like:
# "error getting cloudflare secret: secrets 'cloudflare-api-token' not found"
Step 5: Check Active Challenges
# List all challenges
kubectl get challenge -A
# Describe a specific challenge
kubectl describe challenge <challenge-name> -n infrastructure
Challenges should go from pending to valid. If one stays pending, check:
# Are there any Orders?
kubectl get order -n infrastructure
# Describe the order
kubectl describe order <order-name> -n infrastructure
Step 6: Verify API Token is Working
Your Cloudflare logs tell you whether the token is used at all.
- Go to Cloudflare Dashboard
- Navigate to your domain
- Go to Analytics & Logs → Logs
- Look for API requests
If there are no requests from cert-manager, it isn’t finding or using the token.
Step 7: Check for Domain Mismatch
I had created the API token for example.io but configured the certificates for example.com.
Compare the two:
# What domains are in your certificates?
kubectl get certificate -n infrastructure -o yaml | grep dnsNames -A1
# Does your API token have access to these domains?
Either create a token for the right domain, or change the domain in your YAML files.
To change it everywhere:
# Update certificate domains
sed -i 's/example.li/example.io/g' infrastructure/monitoring/certificates.yaml
# Update IngressRoute domains
sed -i 's/example.li/example.io/g' infrastructure/monitoring/ingressroutes.yaml
# Update Grafana root URL
sed -i 's/example.li/example.io/g' infrastructure/monitoring/helm-values.yaml
# Update ClusterIssuer selector
sed -i 's/example.li/example.io/g' base/clusterissuers/letsencrypt-cloudflare.yaml
# Redeploy
kubectl delete certificate --all -n infrastructure
kubectl delete challenge --all -n infrastructure
kubectl apply -f base/clusterissuers/letsencrypt-cloudflare.yaml
kubectl apply -f infrastructure/monitoring/certificates.yaml
kubectl apply -f infrastructure/monitoring/ingressroutes.yaml
All troubleshooting commands
# 1. Certificate status and details
kubectl get certificate -A
kubectl describe certificate <cert-name> -n <namespace>
# 2. Check secrets
kubectl get secret cloudflare-api-token -n cert-manager
kubectl get sealedsecret -n cert-manager
# 3. Check challenges and orders
kubectl get challenge -A
kubectl get order -n infrastructure
kubectl describe challenge <challenge-name> -n <namespace>
# 4. Controller logs
kubectl logs -n cert-manager deployment/cert-manager --tail=100
kubectl logs -n kube-system -l name=sealed-secrets-controller --tail=50
# 5. ClusterIssuer status
kubectl get clusterissuer
kubectl describe clusterissuer letsencrypt-prod
# 6. Force certificate refresh
kubectl delete challenge --all -n infrastructure
kubectl delete certificate --all -n infrastructure
kubectl apply -f infrastructure/monitoring/certificates.yaml
Once it’s fixed, the certificates should be ready within 2–3 minutes:
$ kubectl get certificate -n infrastructure
NAME READY SECRET AGE
grafana-tls True grafana-tls-secret 3m
prometheus-tls True prometheus-tls-secret 3m
Access Your Monitoring Stack
When the certificates are ready:
- Grafana: https://grafana.example.com (admin / your-password)
- Prometheus: https://prometheus.example.com (admin / your-password)
Phase 9: Deploying n8n with PostgreSQL
Now the actual application. n8n automates workflows, similar to Zapier.
Create PostgreSQL Secret
# Generate secure password
PG_PASSWORD=$(openssl rand -base64 32)
echo "PostgreSQL password: $PG_PASSWORD"
echo "⚠️ Save this password!"
# Create and encrypt secret
cat > secrets/n8n-postgres.yaml <<EOF
apiVersion: v1
kind: Secret
metadata:
name: postgres-secret
namespace: n8n
type: Opaque
stringData:
postgres-password: "$PG_PASSWORD"
postgres-user: "n8n"
postgres-db: "n8n"
EOF
kubeseal --format yaml --cert pub-cert.pem \
< secrets/n8n-postgres.yaml \
> apps/n8n/postgres/secret.enc.yaml
rm secrets/n8n-postgres.yaml
kubectl apply -f apps/n8n/postgres/secret.enc.yaml
Deploy PostgreSQL
# PVC
cat > apps/n8n/postgres/pvc.yaml <<'EOF'
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: postgres-pvc
namespace: n8n
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 10Gi
EOF
# Deployment
cat > apps/n8n/postgres/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres
namespace: n8n
spec:
replicas: 1
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:16-alpine
env:
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: postgres-secret
key: postgres-db
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-secret
key: postgres-user
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: postgres-password
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
ports:
- containerPort: 5432
volumeMounts:
- name: postgres-storage
mountPath: /var/lib/postgresql/data
resources:
requests:
cpu: 100m
memory: 256Mi
limits:
cpu: 500m
memory: 512Mi
volumes:
- name: postgres-storage
persistentVolumeClaim:
claimName: postgres-pvc
EOF
# Service
cat > apps/n8n/postgres/service.yaml <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: postgres
namespace: n8n
spec:
selector:
app: postgres
ports:
- port: 5432
targetPort: 5432
type: ClusterIP
EOF
# Deploy
kubectl apply -f apps/n8n/postgres/
kubectl wait --for=condition=Available --timeout=300s -n n8n deployment/postgres
Create n8n Secret
# Generate encryption key
N8N_KEY=$(openssl rand -hex 32)
echo "n8n encryption key: $N8N_KEY"
echo "⚠️ Save this key!"
# Create and encrypt secret
cat > secrets/n8n-app.yaml <<EOF
apiVersion: v1
kind: Secret
metadata:
name: n8n-secret
namespace: n8n
type: Opaque
stringData:
encryption-key: "$N8N_KEY"
EOF
kubeseal --format yaml --cert pub-cert.pem \
< secrets/n8n-app.yaml \
> apps/n8n/n8n/secret.enc.yaml
rm secrets/n8n-app.yaml
kubectl apply -f apps/n8n/n8n/secret.enc.yaml
Deploy n8n
Replace n8n.example.com with your domain.
# PVC
cat > apps/n8n/n8n/pvc.yaml <<'EOF'
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: n8n-pvc
namespace: n8n
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path
resources:
requests:
storage: 5Gi
EOF
# Deployment
cat > apps/n8n/n8n/deployment.yaml <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: n8n
namespace: n8n
spec:
replicas: 1
selector:
matchLabels:
app: n8n
template:
metadata:
labels:
app: n8n
spec:
containers:
- name: n8n
image: n8nio/n8n:latest
env:
- name: DB_TYPE
value: "postgresdb"
- name: DB_POSTGRESDB_HOST
value: "postgres"
- name: DB_POSTGRESDB_PORT
value: "5432"
- name: DB_POSTGRESDB_DATABASE
valueFrom:
secretKeyRef:
name: postgres-secret
key: postgres-db
- name: DB_POSTGRESDB_USER
valueFrom:
secretKeyRef:
name: postgres-secret
key: postgres-user
- name: DB_POSTGRESDB_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: postgres-password
- name: N8N_ENCRYPTION_KEY
valueFrom:
secretKeyRef:
name: n8n-secret
key: encryption-key
- name: N8N_HOST
value: "n8n.example.com"
- name: N8N_PROTOCOL
value: "https"
- name: WEBHOOK_URL
value: "https://n8n.example.com/"
- name: N8N_SECURE_COOKIE
value: "false"
ports:
- containerPort: 5678
volumeMounts:
- name: n8n-storage
mountPath: /home/node/.n8n
resources:
requests:
cpu: 200m
memory: 512Mi
limits:
cpu: 1000m
memory: 1Gi
volumes:
- name: n8n-storage
persistentVolumeClaim:
claimName: n8n-pvc
EOF
# Service
cat > apps/n8n/n8n/service.yaml <<'EOF'
apiVersion: v1
kind: Service
metadata:
name: n8n
namespace: n8n
spec:
selector:
app: n8n
ports:
- name: http
port: 5678
targetPort: 5678
protocol: TCP
type: ClusterIP
EOF
# Deploy
kubectl apply -f apps/n8n/n8n/
kubectl wait --for=condition=Available --timeout=300s -n n8n deployment/n8n
N8N_SECURE_COOKIE=false is needed because n8n runs behind Traefik and doesn't see that it's being accessed via HTTPS.
Create Certificate and Ingress for n8n
Replace n8n.example.com with your domain.
# Certificate
cat > apps/n8n/ingress/certificate.yaml <<'EOF'
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: n8n-tls
namespace: n8n
spec:
secretName: n8n-tls-secret
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer
dnsNames:
- n8n.example.com
EOF
# Standard Kubernetes Ingress
cat > apps/n8n/ingress/ingress.yaml <<'EOF'
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: n8n-ingress
namespace: n8n
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: websecure
traefik.ingress.kubernetes.io/router.tls: "true"
spec:
ingressClassName: traefik
tls:
- hosts:
- n8n.example.com
secretName: n8n-tls-secret
rules:
- host: n8n.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: n8n
port:
number: 5678
EOF
# Deploy
kubectl apply -f apps/n8n/ingress/
I use a standard Ingress here. Traefik’s IngressRoute can do more, but the standard one was more reliable for me on Rocky Linux 10.
Configure DNS
Add in Cloudflare:
A n8n.example.com → YOUR_SERVER_IP
Wait 2–3 minutes for the certificate, then access: https://n8n.example.com
Phase 10: Verification and Testing
Check that everything is running:
# Check all pods
kubectl get pods -A
# Check certificates
kubectl get certificate -A
# Check storage
kubectl get pvc -A
# Check services
kubectl get svc -A
All pods should be “Running” and all certificates “Ready: True”.
Access Your Services
- Grafana: https://grafana.example.com (admin / your-grafana-password)
- Prometheus: https://prometheus.example.com (admin / your-prometheus-password)
- n8n: https://n8n.example.com (create your admin account on first visit)
Import Traefik Dashboard in Grafana
- Open Grafana
- Go to Dashboards → Import
- Enter dashboard ID: 17346
- Select Prometheus as datasource
- Import
You now see the Traefik metrics in Grafana.
More troubleshooting
Apart from the certificates, these are the problems you are most likely to run into:
Pod Stuck in “Pending” State
What you see:
$ kubectl get pods -n n8n
NAME READY STATUS RESTARTS AGE
postgres-5d7f8c9b4d-abc12 0/1 Pending 0 5m
To find out why:
kubectl describe pod <pod-name> -n <namespace>
Usual causes:
- No storage available:
Events:
Warning FailedScheduling pod has unbound immediate PersistentVolumeClaims
Fix: Check PVC status:
kubectl get pvc -n n8n
kubectl describe pvc postgres-pvc -n n8n
- Resource constraints:
Events:
Warning FailedScheduling Insufficient cpu
Fix: Reduce resource requests in deployment YAML or add nodes.
- Node selector mismatch:
Fix: Remove node selectors in single-node setups.
Pod CrashLoopBackOff
What you see:
$ kubectl get pods -n n8n
NAME READY STATUS RESTARTS AGE
n8n-7d8f9c5b4d-xyz89 0/1 CrashLoopBackOff 5 3m
To find out why:
# Check pod logs
kubectl logs <pod-name> -n <namespace>
# Check previous logs if pod restarted
kubectl logs <pod-name> -n <namespace> --previous
# Watch logs in real-time
kubectl logs <pod-name> -n <namespace> -f
Usual causes:
- Database connection failed (n8n can't reach PostgreSQL):
Error: connect ECONNREFUSED postgres:5432
Fix: Verify PostgreSQL service exists and is running:
kubectl get svc postgres -n n8n
kubectl get pods -n n8n -l app=postgres
- Missing environment variables:
Error: N8N_ENCRYPTION_KEY is required
Fix: Verify secret exists and is referenced correctly:
kubectl get secret n8n-secret -n n8n
kubectl describe deployment n8n -n n8n | grep -A10 env
- Volume mount permissions:
Error: EACCES: permission denied, mkdir '/home/node/.n8n'
Fix: Check PVC and volume mount configuration.
Network/Connectivity Issues — Pod-to-Pod Communication Fails
On Rocky Linux 10, check this first.
Services return 502 Bad Gateway and Traefik can't reach the pods.
What you see:
$ kubectl exec -n infrastructure deployment/traefik -- wget -O- http://10.42.0.29:5678
wget: can't connect to remote host (10.42.0.29): Host is unreachable
But DNS works fine:
$ kubectl exec -n infrastructure deployment/traefik -- wget -O- http://n8n.n8n.svc.cluster.local:5678
# Works! Returns HTML
Rocky Linux 10 uses nftables by default, but Flannel in k3s runs in iptables mode.
See the networking fix in Phase 2. k3s has to run with proxy-mode=iptables.
To check:
# 1. Test pod-to-pod connectivity
TRAEFIK_IP=$(kubectl get pod -n infrastructure -l app.kubernetes.io/name=traefik -o jsonpath='{.items[0].status.podIP}')
N8N_IP=$(kubectl get pod -n n8n -l app=n8n -o jsonpath='{.items[0].status.podIP}')
kubectl exec -n infrastructure deployment/traefik -- wget -O- http://$N8N_IP:5678 --timeout=5
# If you see "Host is unreachable" → networking is broken
# If you see HTML or connection refused → networking works
# 2. Check if k3s is using iptables mode
cat /etc/systemd/system/k3s.service | grep "proxy-mode=iptables"
# Should show: '--kube-proxy-arg' 'proxy-mode=iptables'
# 3. Verify Flannel is running
sudo journalctl -u k3s -n 100 | grep -i flannel
# Should show: "Running flannel backend"
Storage Issues
PVC stuck in “Pending”:
$ kubectl get pvc -A
NAMESPACE NAME STATUS VOLUME CAPACITY ACCESS MODES
n8n postgres-pvc Pending
To find out why:
kubectl describe pvc postgres-pvc -n n8n
Usual causes:
- No storage class:
Events:
Warning ProvisioningFailed storageclass.storage.k8s.io "local-path" not found
Fix: Verify local-path provisioner is running:
kubectl get storageclass
kubectl get pods -n kube-system -l app=local-path-provisioner
If missing (shouldn’t happen with k3s):
kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml
- Disk space full:
# Check node disk space
df -h
# Check k8s storage
kubectl get pv
Fix: Clean up unused volumes or add disk space.
Helm Installation Failures
Helm install fails or times out
Error: timed out waiting for the condition
What helps:
Check specific pod failures:
helm install my-release ... --wait --timeout=10m
kubectl get pods -n <namespace>
kubectl logs <failing-pod> -n <namespace>
Increase timeout:
helm install ... --timeout=15m
Skip wait and debug:
helm install ... --wait=false
# Then manually check what's failing
SealedSecret Not Creating Regular Secret
SealedSecret exists but regular Secret doesn’t appear
To find out why:
# Check SealedSecret status
kubectl get sealedsecret -n <namespace>
kubectl describe sealedsecret <name> -n <namespace>
# Check controller logs
kubectl logs -n kube-system -l name=sealed-secrets-controller --tail=100
Usual causes:
- Encrypted with wrong public key:
Error: unable to decrypt
Fix: Re-encrypt with current cluster key:
# Get current public key
kubeseal --fetch-cert \
--controller-name=sealed-secrets-controller \
--controller-namespace=kube-system \
> pub-cert-current.pem
# Re-encrypt all secrets with current key
kubeseal --format yaml --cert pub-cert-current.pem \
< secrets/my-secret.yaml \
> path/to/my-secret.enc.yaml
- Controller not running:
kubectl get pods -n kube-system | grep sealed-secrets
Fix: Reinstall controller if missing.
Diagnostic commands
Quick health check:
# All pods should be Running
kubectl get pods -A
# All PVCs should be Bound
kubectl get pvc -A
# All certificates should be Ready
kubectl get certificate -A
# All services should have endpoints
kubectl get endpoints -A
# Check recent events across all namespaces
kubectl get events -A --sort-by='.lastTimestamp' | tail -20
A specific resource:
# Get full resource details
kubectl describe <resource-type> <name> -n <namespace>
# Get YAML definition
kubectl get <resource-type> <name> -n <namespace> -o yaml
# Watch resource status changes
kubectl get <resource-type> -n <namespace> -w
Log aggregation:
# Logs from all pods with a label
kubectl logs -n <namespace> -l app=<name> --tail=100
# Logs from all containers in a pod
kubectl logs <pod-name> -n <namespace> --all-containers=true
# Follow logs
kubectl logs <pod-name> -n <namespace> -f
Backup Strategy
Back up the important data:
# Create backup script
cat > ~/k8s/scripts/backup.sh <<'EOF'
#!/bin/bash
set -e
BACKUP_DIR="/root/k8s-backups/$(date +%Y-%m-%d)"
mkdir -p "$BACKUP_DIR"
echo "=== Backing up Sealed Secrets Master Key ==="
kubectl get secret -n kube-system -l sealedsecrets.bitnami.com/sealed-secrets-key \
-o yaml > "$BACKUP_DIR/sealed-secrets-master-key.yaml"
echo "=== Backing up n8n PostgreSQL ==="
kubectl exec -n n8n deployment/postgres -- \
pg_dump -U n8n n8n | gzip > "$BACKUP_DIR/n8n-postgres.sql.gz"
echo "=== Backing up n8n data ==="
kubectl exec -n n8n deployment/n8n -- tar czf - /home/node/.n8n \
> "$BACKUP_DIR/n8n-data.tar.gz"
echo "✓ Backup complete: $BACKUP_DIR"
ls -lh "$BACKUP_DIR"
EOF
chmod +x ~/k8s/scripts/backup.sh
# Test it
~/k8s/scripts/backup.sh
Schedule with cron:
# Edit crontab
crontab -e
# Add daily backup at 2 AM
0 2 * * * /root/k8s/scripts/backup.sh
Adding More Applications
New applications always follow the same steps:
- Create namespace (or use existing)
- Create secrets and encrypt them with kubeseal
- Create deployment + service + PVC
- Create certificate + Ingress
- Add DNS record
Example for a new app:
# 1. Create namespace
kubectl create namespace myapp
# 2. Create and encrypt secrets
cat > secrets/myapp-secret.yaml <<EOF
apiVersion: v1
kind: Secret
metadata:
name: myapp-secret
namespace: myapp
stringData:
password: "$(openssl rand -base64 32)"
EOF
kubeseal --format yaml --cert pub-cert.pem \
< secrets/myapp-secret.yaml \
> apps/myapp/secret.enc.yaml
rm secrets/myapp-secret.yaml
kubectl apply -f apps/myapp/secret.enc.yaml
# 3. Create deployment, service, PVC
# (copy structure from n8n example)
# 4. Create certificate + Ingress
# (copy structure from n8n example)
# 5. Add DNS record in Cloudflare
Performance Tuning for Limited Resources
If you’re running on lower-spec hardware (4GB RAM), adjust these values:
# In helm values and deployment YAMLs, reduce resources:
resources:
requests:
cpu: 50m # Lower from 100m
memory: 128Mi # Lower from 256Mi
limits:
cpu: 500m # Lower from 1000m
memory: 512Mi # Lower from 1Gi
# Reduce Prometheus retention
prometheus:
prometheusSpec:
retention: 7d # Lower from 15d
# Reduce storage sizes
storage: 5Gi # Lower from 10Gi or 20Gi
Security Considerations
What is in place:
- Encrypted secrets that can go into Git
- HTTPS for all services
- BasicAuth on Prometheus
- Network policies can be added
- Most images run as non-root
- Resource limits
What you could add:
- Network Policies: Restrict pod-to-pod communication
- Pod Security Standards: Enforce security policies
- OPA/Gatekeeper: Policy enforcement
- Falco: Runtime security monitoring
What I learned
The main things to watch out for:
- Networking on Rocky Linux 10: nftables and iptables don’t get along here. Set
proxy-mode=iptablesin k3s. - Namespaces: ClusterIssuers look for secrets in
cert-manager. - Domains: the API token has to be for the same domain as the certificates.
- Minimal means minimal: you have to install
tarandopensslyourself. - Cloudflare logs: they show whether cert-manager uses your token.
- Sealed Secrets: they only work on the cluster they were encrypted for.
- Grafana: the secret needs both
admin-userandadmin-password. - Ingress: the standard Ingress was more reliable for me than Traefik’s IngressRoute.
- kubectl: export
KUBECONFIGin your.bashrc.
Resources
- k3s Documentation
- Traefik Documentation
- Sealed Secrets GitHub
- Cert-Manager Documentation
- Prometheus Operator
- n8n Documentation
That’s it
The cluster is running, and every new application follows the same steps. If you run into one of the errors above, I hope this saves you some time.