KevsRobots Learning Platform
80% Percent Complete
By Kevin McAleer, 3 Minutes
Page last updated May 24, 2025

Kubernetes is powerful β but itβs also complex and needs to be properly secured, even in small or home lab clusters like K3s on Raspberry Pi.
This lesson will walk you through essential security best practices, including RBAC, secrets, TLS, and attack surface reduction.
RBAC controls who can do what in your cluster.
Create a read-only role and binding:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: read-only
rules:
- apiGroups: [""]
resources: ["pods", "services"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-only-binding
namespace: default
subjects:
- kind: User
name: devuser
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: read-only
apiGroup: rbac.authorization.k8s.io
Apply it with kubectl apply -f.
π Use service accounts and OIDC for tighter control.
Use Secret resources to manage credentials, API tokens, or sensitive configs.
apiVersion: v1
kind: Secret
metadata:
name: my-secret
type: Opaque
data:
username: dXNlcg==
password: c2VjdXJlcGFzcw==
To create secrets from literal values:
kubectl create secret generic my-secret \
--from-literal=username=user \
--from-literal=password=securepass
Secrets are base64-encoded, not encrypted. For stronger security, use sealed-secrets or Vault.
If you use Traefik or another ingress controller, enable TLS for encrypted connections:
Example with cert-manager and Traefik:
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.13.0/cert-manager.yaml
Then create an Ingress resource with tls: and a Certificate resource.
6443 to the internetRemove unused components using --disable flags during K3s install:
INSTALL_K3S_EXEC="--disable servicelb --disable traefik --disable metrics-server"
Use kubectl auth can-i to check RBAC rules:
kubectl auth can-i create deployments --as devuser
| Task | Recommendation |
|---|---|
| Avoid running as root | Use non-root containers |
| Use namespaces | Isolate environments |
| Keep kubeconfig safe | Restrict permissions and store it securely |
| Regularly update images | Especially public base images |
| Restrict access to nodes | Use SSH keys and firewalls |
You now know how to:
Next up: Final Project
You can use the arrows β β on your keyboard to navigate between lessons.
Comments