在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集群保持健康、安全和高效运行。