Docker Volume and Network Management: Persistent Storage and Network Configuration
Docker volume types (named, bind mount, tmpfs), volume management, network modes (bridge, host, overlay), custom networks and container communication.
Set up single and multi-node Kubernetes clusters with K3s: kubectl usage, deployments and services, and application management with Helm on a VPS.
Kubernetes is the industry standard for container orchestration. However, a full Kubernetes installation can be resource-intensive and complex. K3s is a lightweight Kubernetes distribution developed by Rancher — it delivers all Kubernetes features in a single binary and works excellently in resource-constrained environments like VPS.
| Feature | Full Kubernetes | K3s |
|---|---|---|
| Binary size | ~500MB+ | ~100MB |
| Minimum RAM | 2GB+ | 512MB |
| Setup time | 30-60 min | 5 min |
| Dependencies | Many | Minimal |
| Kubernetes compatibility | Full | Full |
| Production use | Yes | Yes |
K3s is fully compatible with the Kubernetes API. kubectl, Helm, and other Kubernetes tools work seamlessly with K3s. It's ideal for small to medium production environments.
# Minimum requirements
# CPU: 1 core
# RAM: 512MB (recommended: 1GB+)
# Disk: 5GB
# OS: Ubuntu 20.04+, Debian 11+, CentOS 8+
# System update
apt update && apt upgrade -y
# Install required tools
apt install -y curl wget
# Install K3s (server mode)
curl -sfL https://get.k3s.io | sh -
# Check service status after installation
systemctl status k3s
# Check cluster status
kubectl get nodes
# List all pods
kubectl get pods -A
# Copy kubeconfig for kubectl
mkdir -p ~/.kube
cp /etc/rancher/k3s/k3s.yaml ~/.kube/config
chmod 600 ~/.kube/config
# Set KUBECONFIG environment variable
export KUBECONFIG=~/.kube/config
echo 'export KUBECONFIG=~/.kube/config' >> ~/.bashrc
# View cluster info
kubectl cluster-info
# Install master node and save token
curl -sfL https://get.k3s.io | sh -
# Get node token (required for worker nodes)
cat /var/lib/rancher/k3s/server/node-token
# Output: K10xxx...::server:yyy...
# Join worker node to master
curl -sfL https://get.k3s.io | K3S_URL=https://MASTER_IP:6443 K3S_TOKEN=NODE_TOKEN sh -
# Verify worker joined on master
kubectl get nodes
# NAME STATUS ROLES AGE
# master-node Ready control-plane,master 10m
# worker-node1 Ready <none> 2m
# List nodes
kubectl get nodes
kubectl get nodes -o wide # Detailed info
# List pods
kubectl get pods
kubectl get pods -n kube-system # System pods
kubectl get pods -A # All namespaces
# List deployments
kubectl get deployments
# List services
kubectl get services
# List namespaces
kubectl get namespaces
# View resource details
kubectl describe pod POD_NAME
kubectl describe node NODE_NAME
# View pod logs
kubectl logs POD_NAME
kubectl logs -f POD_NAME # Live logs
# Run command in pod
kubectl exec -it POD_NAME -- /bin/bash
# nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
# Apply deployment
kubectl apply -f nginx-deployment.yaml
# Check deployment status
kubectl get deployments
kubectl rollout status deployment/nginx-deployment
# List pods
kubectl get pods -l app=nginx
# nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30080
type: NodePort
# Apply service
kubectl apply -f nginx-service.yaml
# Check service
kubectl get services
# Access via browser: http://SERVER_IP:30080
# Create namespaces
kubectl create namespace production
kubectl create namespace staging
# Deploy to namespace
kubectl apply -f deployment.yaml -n production
# List resources in namespace
kubectl get all -n production
# Change default namespace
kubectl config set-context --current --namespace=production
# Install Helm
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
# Check Helm version
helm version
# Add Bitnami repository
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
# Install WordPress
helm install my-wordpress bitnami/wordpress \
--set wordpressUsername=admin \
--set wordpressPassword=StrongPass123! \
--set service.type=NodePort
# List installed charts
helm list
# Remove chart
helm uninstall my-wordpress
# pvc.yaml — Persistent Volume Claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: app-data
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-path # K3s default storage class
resources:
requests:
storage: 5Gi
# Create PVC
kubectl apply -f pvc.yaml
# Check PVC status
kubectl get pvc
# List storage classes
kubectl get storageclass
# Create ConfigMap
kubectl create configmap app-config \
--from-literal=DB_HOST=localhost \
--from-literal=APP_ENV=production
# Create Secret
kubectl create secret generic app-secret \
--from-literal=DB_PASSWORD=StrongPass123! \
--from-literal=API_KEY=abc123
# View ConfigMap
kubectl get configmap app-config -o yaml
# View Secret (base64 encoded)
kubectl get secret app-secret -o yaml
# Update K3s
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.28.0+k3s1 sh -
# Manage K3s service
systemctl stop k3s
systemctl start k3s
systemctl restart k3s
# View K3s logs
journalctl -u k3s -f
# Uninstall K3s
/usr/local/bin/k3s-uninstall.sh
# Remove worker node
/usr/local/bin/k3s-agent-uninstall.sh
# Install Kubernetes Dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
# Create admin user
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
EOF
# Generate token
kubectl -n kubernetes-dashboard create token admin-user
# Start proxy for dashboard access
kubectl proxy
# http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
K3s delivers the full power of Kubernetes with minimal resource usage. It's an ideal solution for production-grade container orchestration in VPS environments. With K3s on REXE servers, you can easily scale your applications, ensure high availability, and implement modern DevOps practices.
K3s is a lightweight distribution fully compatible with the Kubernetes API. Differences: K3s is a single binary (~100MB), while full Kubernetes requires multiple components. K3s can use SQLite (instead of etcd), consumes less RAM (512MB vs 2GB+), and installs much faster. Both are suitable for production use.
First check events with kubectl describe pod POD_NAME. Common issues: 1) Insufficient resources (check with kubectl describe node), 2) Image pull error (test with docker pull), 3) PVC can't bind (check with kubectl get pvc), 4) Missing ConfigMap/Secret. Also check application logs with kubectl logs POD_NAME.
Three methods: 1) NodePort Service: opens a port between 30000-32767, accessed via IP:PORT directly. 2) LoadBalancer Service: works with Klipper LB in K3s. 3) Ingress Controller: provides domain-based access to multiple apps over a single IP (recommended). Traefik comes bundled with K3s by default.
View default values with helm show values CHART_NAME. Create a values.yaml file for customization and use it with helm install -f values.yaml. Alternatively, pass individual values with --set key=value. Use helm upgrade to update an existing installation.
Check: 1) Verify port 6443 on master is reachable from worker (telnet MASTER_IP 6443), 2) Confirm NODE_TOKEN is correct (cat /var/lib/rancher/k3s/server/node-token), 3) Verify port 6443 is open in firewall, 4) Check k3s-agent service logs on worker (journalctl -u k3s-agent -f).
Docker volume types (named, bind mount, tmpfs), volume management, network modes (bridge, host, overlay), custom networks and container communication.
Docker log drivers, the docker logs command, Kubernetes pod logs, centralized logging with Loki or the ELK Stack, log rotation and production practices.
Docker security best practices: non-root user, read-only filesystem, seccomp, image scanning, Docker socket security, network isolation and secrets.