k8s 场景异常时的运维处理记录(三)
Q1.services中endpoints无法识别
kubectl describe service nginx-v1-svc-deploy
无法通过节点来访问pods 容器服务
正常情况如下:
kubectl describe service nginx-service-nodeport
能绑定到容器里的IP
原因:
yaml文件中的name 标识命名不规范
services文件
nginx-v1-svc-deploy.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-v1-svc-deploy
spec:
ports:
- port: 8001
targetPort: 80
protocol: TCP
type: NodePort
selector:
name: nginxv1 (原名称:nginx-v1-svc-deploy )
deploy文件
nginx-v1-pods-deploy.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-v1-pods-deploy
spec:
replicas: 2
template:
metadata:
labels:
name: nginxv1(原名称:nginx-v1-svc-deploy )
spec:
containers:
- name: nginxv1(原名称:nginx-v1-svc-deploy )
image: k8s1:5000/nginx:v1
ports:
- containerPort: 80
Q2:master上无法访问cluster IP
因为无路由及kube-proxy模块
Q3.pod 升级回滚错误
[root@k8s1 opt]# kubectl rolling-update nginx-controller nginx-v1 --image=k8s1:5000/nginx:v1 --update-period=10s
error: Found existing in-progress update to image (nginx:v1).
Either continue in-progress update with --image=nginx:v1 or rollback with --rollback
See 'kubectl rolling-update -h' for help and examples.
由于执行过
kubectl rolling-update nginx-controller nginx-v1 --image=nginx:v1
需要回退
kubectl rolling-update nginx-controller nginx-v1 --rollback
Q4.pod 出现 CrashLoopBackOff
查看Pod对应的节点
kubectl get pods -o wide
查看Pod 详细信息
kubectl describe pods nginx-v1-deploy-6d6d7d48c6-vf6xt
提示错误
Back-off restarting failed container
可能升级方式不对使用 editor
更换为:
kubectl set image deployment/nginx-v1-deploy nginx-v1-deploy=k8s4:5000/nginx:v1.12.2
检查进度
kubectl rollout status deployment/nginx-v1-deploy
Q5. 报权限问题
Error from server (Forbidden): Forbidden (user=system:anonymous, verb=get, resource=nodes, subresource=proxy) ( pods/log nginx-v1-deploy-6d6d7d48c6-vf6xt)
临时赋权
kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous
Q6:配置kubectl子命令补全
[root@master1 work]# yum install -y bash-completion
[root@master1 work]# source /usr/share/bash-completion/bash_completion
[root@master1 work]# source <(kubectl completion bash)
[root@master1 work]# kubectl completion bash > ~/.kube/completion.bash.inc
[root@master1 work]# source '/root/.kube/completion.bash.inc'
[root@master1 work]# source $HOME/.bash_profile
kubeclt 执行流程