在CentOS上部署Kubernetes(k8s)后,進行維護是非常重要的。以下是一些基本的維護步驟和建議:
kubectl get nodes
、kubectl get pods --all-namespaces
等命令定期檢查集群狀態。sudo yum update -y kubelet kubeadm kubectl
kubeadm upgrade
命令。sudo kubeadm upgrade apply v1.23.0
apiVersion: v1
kind: ResourceQuota
metadata:
name: example-quota
namespace: example-namespace
spec:
hard:
requests.cpu: "1"
requests.memory: 1Gi
limits.cpu: "2"
limits.memory: 2Gi
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa
namespace: example-namespace
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: example-deployment
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
sudo kubeadm alpha certs renew all
etcdctl snapshot save /var/lib/etcd/backup/snapshot.db
kubectl
命令備份重要的Kubernetes資源(如ConfigMaps、Secrets)。kubectl get configmap example-configmap -o yaml > example-configmap.yaml
kubectl get events
命令查看集群中的事件日志,幫助診斷問題。kubectl exec
命令進入Pod進行調試。kubectl exec -it <pod-name> -- /bin/sh
通過以上步驟,可以確保CentOS上部署的Kubernetes集群保持健康、安全和高效運行。