预告 3换一个镜像 tag,看新旧交替。现在跑的是
+ registry.local/aurora/shop-api:v1.2.3,改 tag 就是一次发布。
+
+
# env: all
+kubectl set image deployment/shop-api -n shop \
+ shop-api=registry.local/aurora/shop-api:v1.2.4
+kubectl rollout status deployment/shop-api -n shop
+
+
# 预期输出(预告)
+deployment.apps/shop-api image updated
+Waiting for deployment "shop-api" rollout to finish: 1 out of 3 new replicas have been updated
+deployment "shop-api" successfully rolled out
+
+
三条命令都指向同一件事:命令返回时现实还没变完,变的是之后的几秒。
+
+
+ 易错点 · apply 返回 created 就代表上线成功
+
现象:apply 打印 created,紧接 kubectl get pods -n shop 却一个 Pod 都没有;或者有 Pod,但 READY 是 0/1。
+
原因:apply 只写期望状态。建 Pod 的是 Deployment 控制器,拉镜像的是 kubelet,都在它返回之后。
+
怎么验证:apply 完立刻 kubectl get pods -n shop,再跑
+ kubectl rollout status deployment/shop-api -n shop——后者阻塞到收敛,前者不会。
+
+
+
+ 易错点 · Pod 是 Running 就代表业务正常
+
现象:kubectl get pods 一片绿,接口仍返回 502。
+
原因:Running 只说明主进程没退出。没有就绪探针时,Pod 一 Running 就被 Service 当成可用后端。
# 报错原文
+Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
+System has not been booted with systemd as init system (PID 1). Can't operate.
两个值不一样就是答案:/mnt/c 不是 ext4(常见 9p,个别版本 drvfs),
+ 都是 Windows 盘驱动。仓库根再写三行 .gitattributes(* text=auto、*.sh text eol=lf、
+ Makefile text eol=lf),否则 Windows 编辑器存过的脚本带 CRLF,报错是
+ bad interpreter: /bin/bash^M。
注入:先让另一个进程占住 80(Windows 上开 IIS 或某个本地服务),再 make up。
+
症状:创建 control-plane 时报
+ Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:80 -> ...: bind: address already in use。
+
Windows 上还可能报 bind: An attempt was made to access a socket in a way forbidden by its access
+ permissions.——不是被占用,而是 Hyper-V 的保留端口段盖住了 80(
+ netsh interface ipv4 show excludedportrange protocol=tcp 可查)。
周四 21:10,shop-api 开始返回 502。三个人同时上手,十分钟后得出三个矛盾的结论。甲敲
+ kubectl get pods,得到 No resources found in default namespace.,判断 Pod 被删光了。乙看到
+ shop-api 好端端 Running,判断是网络问题。丙的终端连不上,只留一行:
+
+
# 预期输出
+The connection to the server localhost:8080 was refused - did you specify the right host or port?
现象:get node aurora-worker -o yaml > node.yaml 后 apply,报
+ (Conflict): Operation cannot be fulfilled on nodes "aurora-worker": the object has been modified。
# env: all
+kubectl create namespace shop
+kubectl get ns
+kubectl get ns shop --show-labels
+
# 预期输出
+namespace/shop created
+NAME STATUS AGE
+default Active 22m
+kube-node-lease Active 22m
+kube-public Active 22m
+kube-system Active 22m
+local-path-storage Active 22m
+shop Active 4s
+
+NAME STATUS AGE LABELS
+shop Active 12s <none>
# env: all
+kubectl get pods -n sho
+kubectl get pods -n shop
+kubectl get events -n shop
+
# 预期输出
+Error from server (NotFound): namespaces "sho" not found
+No resources found in shop namespace.
+No resources found in shop namespace.
+
+
两种输出对应两种结论:NotFound 是没建,No resources found 是建了但空。分不清这两句,
+ 就会在「对象被删了」和「我打错字了」之间横跳。第三条为空还有一层原因:events 挂在对象上。
+
+
Step 5 · 让 events 说话 建立「先看事件时间线」的条件反射。
+
# env: all
+kubectl get events -A --sort-by=.lastTimestamp | tail -n 8
+kubectl get events -n kube-system --field-selector type=Warning
+kubectl get events -A --field-selector involvedObject.name=aurora-worker
+
# 预期输出
+NAMESPACE LAST SEEN TYPE REASON OBJECT MESSAGE
+kube-system 2m41s Normal Scheduled pod/coredns-6f7c9d8b5-4m2xk Successfully assigned kube-system/coredns-6f7c9d8b5-4m2xk to aurora-control-plane
+kube-system 2m38s Normal Pulled pod/coredns-6f7c9d8b5-4m2xk Container image "registry.k8s.io/coredns/coredns:v1.12.1" already present on machine
+kube-system 2m36s Normal Created pod/kindnet-x7k2p Created container kindnet-cni
+default 48s Normal Starting node/aurora-worker Starting kubelet.
+default 41s Normal NodeReady node/aurora-worker Node aurora-worker status is now: NodeReady
+
+No resources found in kube-system namespace.
+
+NAMESPACE LAST SEEN TYPE REASON OBJECT MESSAGE
+default 41s Normal NodeReady node/aurora-worker Node aurora-worker status is now: NodeReady
+default 48s Normal Starting node/aurora-worker Starting kubelet.
# env: all
+kubectl get nodes -L kubernetes.io/hostname,node-role.kubernetes.io/control-plane
+kubectl get nodes -l node-role.kubernetes.io/control-plane
+kubectl get nodes --field-selector metadata.name=aurora-worker
+kubectl get pods -n kube-system --field-selector status.phase!=Running
+
# 预期输出
+NAME STATUS ROLES AGE VERSION HOSTNAME CONTROL-PLANE
+aurora-control-plane Ready control-plane 24m v1.36.1 aurora-control-plane
+aurora-worker Ready <none> 23m v1.36.1 aurora-worker
+
+NAME STATUS ROLES AGE VERSION
+aurora-control-plane Ready control-plane 24m v1.36.1
+
+NAME STATUS ROLES AGE VERSION
+aurora-worker Ready <none> 23m v1.36.1
+
+No resources found in kube-system namespace.
+
+
最后一条在刚建好的集群里是空的,因为 kube-system 的 Pod 全在 Running;一旦有 Pod 卡在
+ Pending 或 Completed,它就会把行列出来——这正是排障时最快的那一刀。
# env: all
+kubectl get ns
+kubectl get all,cm,secret,pvc,ingress -n shop
+
# 预期输出
+NAME STATUS AGE
+default Active 46m
+kube-node-lease Active 46m
+kube-public Active 46m
+kube-system Active 46m
+local-path-storage Active 46m
+shop Active 24m
+
+No resources found in shop namespace.
+
+
残留检查要读懂两件事:shop 还在,说明边界没被误删;No resources found 说明本章没留下工作负载。
+ 回滚上一章用
+ git checkout HEAD~1 -- Makefile deploy/base/,再跑 make verify-ch01 确认回到 S0 起点。