Restart a Service

Procedures for restarting services on MEGATRON, covering K3s pods, systemd services, and Docker containers.

Kubernetes Pod / Deployment

# Restart a deployment (graceful rolling restart)
kubectl rollout restart deployment/<name> -n <namespace>

# Restart a statefulset
kubectl rollout restart statefulset/<name> -n <namespace>

# Delete a pod (it will be recreated by its controller)
kubectl delete pod <pod-name> -n <namespace>

# Force delete a stuck pod
kubectl delete pod <pod-name> -n <namespace> --grace-period=0 --force

# Check rollout status
kubectl rollout status deployment/<name> -n <namespace>

Systemd Service

# Restart a service
sudo systemctl restart <service-name>

# Stop and start
sudo systemctl stop <service-name>
sudo systemctl start <service-name>

# Check status
sudo systemctl status <service-name>

# View logs
journalctl -u <service-name> --since "5 minutes ago"

Key services:

  • k3s.service -- K3s server (WARNING: restarts entire control plane)
  • sshd.service -- SSH daemon
  • sshd-rescue.service -- Rescue SSH
  • cloudflared.service -- Cloudflare tunnel
  • tailscaled.service -- Tailscale VPN
  • docker.service -- Docker daemon

Docker Container

# Restart a container
docker restart <container-name>

# Stop and start
docker stop <container-name>
docker start <container-name>

# Restart entire compose stack
cd /path/to/project && docker compose restart

# Rebuild and restart
docker compose up -d --build <service-name>

Cautions

  • k3s.service: Restarting K3s disrupts all pods. Only restart during planned maintenance.
  • docker.service: Restarting Docker stops all non-K3s containers.
  • cloudflared.service: Restarting interrupts all external traffic for a few seconds.