Connection
Check config file location
cat /etc/rancher/k3s/k3s.yaml
Export KUBECONFIG
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
Access K3s from non-server hosts
scp root@k3s-server:/etc/rancher/k3s/k3s.yaml ~/.kube/config
Installation and Management
Install K3s as server
curl -sfL https://get.k3s.io | sh -
Install K3s as agent
curl -sfL https://get.k3s.io | K3S_URL=https://server-url:6443 K3S_TOKEN=mynodetoken sh -
Stop K3s service
systemctl stop k3s
Start K3s service
systemctl start k3s
Check K3s service status
systemctl status k3s
Uninstall K3s
/usr/local/bin/k3s-uninstall.sh
Cluster Information
Get nodes
kubectl get nodes
Get node details
kubectl describe node
Get cluster info
kubectl cluster-info
Get K3s version
k3s --version
Pod and Deployment Management
List all pods
kubectl get pods --all-namespaces
List pods in a namespace
kubectl get pods -n
Get pod details
kubectl describe pod -n
Get pod logs
kubectl logs -n
Execute command in pod
kubectl exec -it -n --
Service Management
List all services
kubectl get svc --all-namespaces
Get service details
kubectl describe svc -n
Create service
kubectl apply -f service.yaml
Resource Monitoring
Get resource usage
kubectl top nodes
Get pod resource usage
kubectl top pods -n
Monitor K3s logs
journalctl -u k3s
Configuration and Security
View K3s config
cat /etc/systemd/system/k3s.service.env
Get secrets
kubectl get secrets -n
Manage K3s tokens
cat /var/lib/rancher/k3s/server/node-token