KUBERNETES ON BARE METAL

When k3s earns its keep, and how to run a production Kubernetes cluster on a dedicated server: install, TLS, storage, HA and backups.

Kubernetes on bare metal with k3s

 

Kubernetes on bare metal with k3s

Running Kubernetes on bare metal with k3s gives you the full Kubernetes API on hardware you control, without a managed control-plane bill or per-cluster fees. This guide sets up a self-hosted Kubernetes cluster on a dedicated server running Ubuntu 24.04 LTS, from a single-node install to a three-node high-availability cluster, with real commands you can paste and run.

Before any of that, an honest question: do you actually need Kubernetes? Most single-box teams do not, and this guide starts by saying so. If you decide you do, everything below gets you to a working k3s production setup with TLS, sane storage and tested backups.

First, do you even need Kubernetes?

Kubernetes is a distributed systems platform. It is worth learning only when you have a distributed systems problem. If you run a handful of containers on one server, Docker Compose does the same job with a fraction of the moving parts: one YAML file, ordinary Linux tools when something breaks, no control plane to keep alive. For that case, follow our production Docker host guide and stop there. Do not add Kubernetes for the resume line.

k3s earns its keep in specific situations. You want the Kubernetes API itself: GitOps with Argo CD or Flux, operators that manage databases or certificates for you, Helm charts as your unit of deployment. Your team already speaks Kubernetes and wants one language everywhere. You need staging that mirrors a cloud cluster your production runs on. Or you are about to grow past one node and want scheduling, self-healing and rolling deploys across several machines. If one of those is true, read on. If none is, save yourself the complexity.

Why bare metal and k3s are a strong combination

When you do want Kubernetes, running it on a dedicated server is a good deal. On a managed cloud service you pay a monthly fee per cluster for the control plane before you run a single workload, then again for load balancers and network-attached volumes. On bare metal there is no control-plane bill and no per-cluster fee: every core and every gigabyte of RAM goes to your workloads, and k3s runs its own control plane in a few hundred megabytes. Storage is local NVMe at full speed, not a throttled network volume billed by the IOPS.

Be clear about what you give up. There is no managed upgrade button: you patch the nodes and the cluster yourself. There is no cloud load balancer provisioning a public IP on demand, and no storage driver that spins up replicated volumes across availability zones. You get those things by running the pieces yourself, which this guide covers, or by keeping stateful data outside the cluster. For a team that wants the Kubernetes API without the cloud tax, that trade is usually worth it.

What k3s actually is

k3s is upstream Kubernetes, repackaged for the real world. It is a fully conformant Kubernetes distribution shipped as a single small binary, built by Rancher (now SUSE) and widely run in production. It bundles the batteries a cluster needs so you are not assembling them by hand: containerd as the runtime, Flannel for pod networking, Traefik as the ingress controller, a built-in service load balancer (servicelb) so Services of type LoadBalancer get an IP on bare metal, and local-path as the default storage provisioner. You write the same manifests and use the same kubectl as any Kubernetes cluster; k3s just makes the install and the footprint sane.

Install k3s on a single node

Before you install anything, secure the server. Follow our getting-your-server-online guide: change the delivered root password, create an admin user with an SSH key, disable password login, apply all updates and turn on unattended security patches. A Kubernetes API is a powerful thing to leave exposed, so the host firewall matters here more than usual. These commands are for Ubuntu 24.04 LTS.

Install k3s with the official script. Pin the release channel so you know what you are getting and upgrades are deliberate. Replace 203.0.113.10 with your server's public IP: passing it as a TLS SAN makes the API certificate valid for that address, so you can reach the cluster from your laptop later.

Install the k3s server, pinned to the stable channel, with your public IP added to the API certificate.

shell
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=stable sh -s - --tls-san 203.0.113.10

Check what the installer started. You get a running node, the system pods and the bundled Traefik ingress, all under a systemd service called k3s.

shell
sudo systemctl status k3s --no-pager
sudo k3s kubectl get nodes
sudo k3s kubectl get pods -A

The installer wrote a kubeconfig to /etc/rancher/k3s/k3s.yaml. On the server, "sudo k3s kubectl" already uses it. To drive the cluster from your laptop instead, copy that file down and point it at the public IP, because the file ships with a server address of 127.0.0.1 that only works locally.

kubectl from your laptop, and lock down the API

Copy the kubeconfig to your workstation, swap the loopback address for the server's public IP, and you can run kubectl locally. This assumes you already have kubectl installed on your laptop.

Pull the kubeconfig down and rewrite the API address to your server's public IP.

shell
scp root@203.0.113.10:/etc/rancher/k3s/k3s.yaml ~/.kube/serverbiz.yaml
sed -i 's/127.0.0.1/203.0.113.10/' ~/.kube/serverbiz.yaml
export KUBECONFIG=~/.kube/serverbiz.yaml
kubectl get nodes

The API on port 6443 is now reachable. Do not leave it open to the internet. Allow it only from your admin IP (or, better, only over a private network or WireGuard), and let the ports the cluster actually serves through: 80 and 443 for Traefik ingress.

shell
sudo ufw default deny incoming
sudo ufw allow OpenSSH
sudo ufw allow from YOUR_ADMIN_IP to any port 6443 proto tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

The Kubernetes API is the keys to the whole cluster. Anyone who can reach port 6443 with the kubeconfig can run anything. Restricting it to your admin IP is the minimum; putting it behind WireGuard so it is never on the public internet at all is better. On a single-node box you can also skip publishing 6443 entirely and reach it through an SSH tunnel.

Deploy a real app with automatic TLS

Now deploy something real: a web app behind the Traefik ingress, with a real Let's Encrypt certificate issued automatically. First install cert-manager, which watches for Ingress resources and provisions certificates for them. Set KUBECONFIG so helm talks to your cluster, then install the chart.

Install cert-manager with Helm, including its custom resource definitions.

shell
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager \
  --namespace cert-manager --create-namespace \
  --set crds.enabled=true

Create a ClusterIssuer that gets certificates from Let's Encrypt over the HTTP-01 challenge, solved through Traefik. Replace the email with a real address you monitor; Let's Encrypt sends expiry warnings there.

clusterissuer.yaml
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: you@YOUR_DOMAIN
    privateKeySecretRef:
      name: letsencrypt-prod
    solvers:
      - http01:
          ingress:
            class: traefik

The app itself: a Deployment of two replicas, a Service in front of them, and an Ingress that requests a certificate and routes your hostname to the Service. Replace YOUR_DOMAIN with a hostname whose A record (and AAAA for IPv6) already points at this server.

web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginxdemos/hello:plain-text
          ports:
            - containerPort: 80
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 250m
              memory: 128Mi
---
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
    - port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: traefik
  tls:
    - hosts:
        - YOUR_DOMAIN
      secretName: web-tls
  rules:
    - host: YOUR_DOMAIN
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 80

Apply both, then watch the certificate go from pending to ready. Once it is ready, https://YOUR_DOMAIN serves with a valid certificate.

shell
kubectl apply -f clusterissuer.yaml
kubectl apply -f web.yaml
kubectl get certificate -w

The HTTP-01 challenge needs port 80 reachable from the internet, which is why the firewall step opened it. cert-manager renews the certificate automatically well before it expires, so this is set-and-forget. Notice the resources block on the container: requests and limits are not optional on a shared box, and the next sections come back to why.

Storage on bare metal: the honest version

This is where bare-metal Kubernetes bites people, so be deliberate. k3s ships local-path as the default storage class. It is real, fast NVMe, and it works perfectly on one node. The catch: a local-path volume lives on one specific node's disk. On a single-node cluster that is fine. The moment you have several nodes, a pod using a local-path volume can only run on the node that holds its data, and if that node dies the data is gone with it. local-path is node-pinned storage, nothing more.

You have two honest ways forward for a multi-node cluster. The first is Longhorn: a storage system that replicates each volume across several nodes, so a pod can move and its data follows. It needs open-iscsi on every node and enough disk for the replicas (three replicas means three copies of the data). The second, and often the better one, is to keep state out of the cluster entirely: run your database on a dedicated database server and let the cluster hold only stateless workloads. Our production database server guide covers that pattern, and for many teams it is simpler and faster than replicated in-cluster storage.

If you go the Longhorn route, install open-iscsi on every node first, then the chart. defaultReplicaCount of 3 means each volume survives losing two nodes; drop it to match your node count.

shell
sudo apt-get update && sudo apt-get install -y open-iscsi nfs-common
helm repo add longhorn https://charts.longhorn.io
helm repo update
helm install longhorn longhorn/longhorn \
  --namespace longhorn-system --create-namespace \
  --set defaultSettings.defaultReplicaCount=3

Replicated storage is not free: every write goes to several disks over the network, so it is slower than raw local NVMe, and it uses several times the raw capacity. That is the price of a volume that survives a node dying. If your stateful load is a single primary database, an external database server usually beats it on both speed and simplicity. Reach for Longhorn when you genuinely need in-cluster persistent volumes that follow their pods.

Growing to a three-node HA cluster

A single node has a single point of failure: itself. To survive a machine dying you need at least three nodes and a replicated control-plane datastore. One important detail up front: the default single-node install uses an embedded SQLite database, which cannot form a cluster. If you know you will grow, install the first server with the --cluster-init flag so it uses embedded etcd from the start. If you already installed with SQLite, you reinstall the first server with --cluster-init before adding the others.

High availability with embedded etcd needs an odd number of servers so the cluster can hold quorum: three is the standard choice, surviving the loss of one. Get the node token from the first server, then join two more servers and any number of agents (worker-only nodes). Join over a private network wherever you can: pass the private interface address so cluster traffic never crosses the public internet. The datacenter partner offers private networking between machines in the same location, or you can build a WireGuard mesh yourself.

On the first server, if you are starting fresh and plan to grow, initialise the cluster with embedded etcd.

shell
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=stable sh -s - server \
  --cluster-init \
  --tls-san 203.0.113.10

Read the join token from the first server. You will paste it into the other nodes.

shell
sudo cat /var/lib/rancher/k3s/server/node-token

Join the second and third servers to form the HA control plane. 10.0.0.1 is the first server's private address; YOUR_TOKEN is the token you just read.

shell
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=stable sh -s - server \
  --server https://10.0.0.1:6443 \
  --token YOUR_TOKEN \
  --node-ip 10.0.0.2

Add a worker-only agent node the same way. Agents run workloads but hold no control-plane state.

shell
curl -sfL https://get.k3s.io | K3S_URL=https://10.0.0.1:6443 K3S_TOKEN=YOUR_TOKEN sh -

Check "kubectl get nodes" and you should see all three servers Ready. With three etcd members the cluster keeps running and stays writable through the loss of any one node. Never run two servers and call it HA: with an even count, losing one leaves you without quorum and the cluster goes read-only, which is worse than a single node.

Operations: upgrades, drains, backups and limits

Because you own the cluster, four routine jobs are yours. Upgrading k3s on a node is a re-run of the install script on the same channel: it fetches the newer release and restarts the service in place. On a multi-node cluster, drain the node first so its pods move elsewhere, upgrade it, then bring it back. Do the servers one at a time so quorum holds throughout.

Drain a node before maintenance, so its workloads reschedule onto the others.

shell
kubectl drain NODE_NAME --ignore-daemonsets --delete-emptydir-data

Upgrade k3s on that node by re-running the installer on the pinned channel, then let it back into rotation.

shell
curl -sfL https://get.k3s.io | INSTALL_K3S_CHANNEL=stable sh -
kubectl uncordon NODE_NAME

On an etcd cluster, k3s takes scheduled etcd snapshots automatically, and you can take one on demand before any risky change. Snapshots land in /var/lib/rancher/k3s/server/db/snapshots.

shell
sudo k3s etcd-snapshot save --name pre-upgrade
sudo k3s etcd-snapshot list

A snapshot on the same machine is not a backup. Copy the snapshot directory offsite on a schedule, to a separate backup and storage server or object storage.

shell
rsync -a /var/lib/rancher/k3s/server/db/snapshots/ \
  backups@203.0.113.20:/srv/k3s-snapshots/

The etcd snapshot is your whole cluster state: every manifest, secret and config. With it you can rebuild a dead control plane from k3s server --cluster-reset. Our server backup strategy guide covers the offsite and retention side properly; treat these snapshots as first-class backups. The fourth job is discipline, not a command: set resource requests and limits on every workload. Requests let the scheduler place pods sensibly; limits stop one runaway container eating the whole box and starving everything else. A LimitRange gives every pod a sane default even when someone forgets.

Apply a LimitRange per namespace so no pod ever runs unbounded, even if its manifest omits resources.

Default resource limits so nothing eats the box

This LimitRange sets a default request and limit for any container in the namespace that does not specify its own. It is the safety net behind the per-pod resources you already set on the web app.

Apply a namespace default. Any container without its own resources inherits these.

limitrange.yaml
apiVersion: v1
kind: LimitRange
metadata:
  name: default-limits
  namespace: default
spec:
  limits:
    - default:
        cpu: 500m
        memory: 512Mi
      defaultRequest:
        cpu: 100m
        memory: 128Mi
      type: Container

Monitoring the cluster

You want to see inside the cluster: pod restarts, node pressure, memory headroom. The kube-prometheus-stack Helm chart installs Prometheus, Alertmanager and Grafana with Kubernetes dashboards already wired up, in one command. It gives you the cluster-level view; the underlying host layer (disk SMART, RAID state, raw node metrics) is a separate concern that our self-hosted monitoring guide covers.

Install the full Prometheus and Grafana stack into its own namespace.

shell
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install monitoring prometheus-community/kube-prometheus-stack \
  --namespace monitoring --create-namespace

Do not expose Grafana straight to the internet. Reach it through kubectl port-forward, or put it behind the same Traefik ingress with its own authentication. The metrics endpoints in this stack are meant to stay inside the cluster.

Compose, single-node k3s, or a three-node cluster

Three sensible stopping points, in rising order of both capability and effort. Pick the leftmost one that meets your need; do not pay for a column you will not use.

Compose on one box k3s, single node k3s, 3-node HA
Kubernetes API No Yes Yes
Survives a node failure No No Yes
Ops burden Lowest Moderate Highest
Storage Local disk Local-path NVMe Longhorn or external DB
Best for A few containers, one team You want the k8s API on one box Production HA across machines

The short version

If a handful of containers on one server is your reality, run Docker Compose and skip this entirely. If you need the Kubernetes API, GitOps, operators or cloud-cluster parity, k3s on a dedicated server gives it to you cheaply: full hardware for your workloads, no control-plane bill. Start single-node, secure the API behind your admin IP or WireGuard, deploy behind Traefik with cert-manager for TLS, keep state on an external database or Longhorn, and grow to three etcd servers only when you truly need to survive a machine dying. Snapshot etcd, copy it offsite, and set resource limits on everything.

Continue reading

Need help choosing?

Our experts can help you find the perfect server for your needs.

Contact us »