Kubernetes (K8s) 日常运维指南

刘小猪 发布于 阅读:3 教程

Kubernetes (K8s) 日常运维指南

Kubernetes 已经是云原生时代的标配,日常运维中我们需要熟练掌握一些 kubectl 命令。以下是日常高频使用的运维操作:

1. 查看集群和节点状态

# 查看节点状态
kubectl get nodes -o wide

# 查看命名空间
kubectl get namespaces

2. Pod 相关操作

# 查看所有 Pod
kubectl get pods -A

# 查看特定命名空间的 Pod
kubectl get pods -n default

# 详细描述 Pod,用于排查启动失败问题
kubectl describe pod <pod-name> -n <namespace>

# 查看 Pod 日志
kubectl logs -f <pod-name> -n <namespace>

# 进入 Pod 容器调试
kubectl exec -it <pod-name> -n <namespace> -- /bin/bash

3. Service 与 Ingress

# 查看 Service
kubectl get svc

# 查看 Ingress
kubectl get ingress

# 端口转发 (本地调试)
kubectl port-forward <pod-name> 8080:80 -n <namespace>

4. 常见故障排查

日常运维中,保持集群的监控(如 Prometheus + Grafana)和日志系统(如 ELK / EFK)的正常运行,能极大地提升排查问题的效率。