当前位置: 首页 > news >正文

02 基本介绍及Pod基础排错

01 yaml文件里的字段错误

# 多打了一个i导致的报错
[root@master01 yaml]# cat 01-pod.yaml 
apiVersion: v1
kind: Pod
metadata:name: likexy
spec:contaiiners:- name: aaaimage: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1
[root@master01 yaml]# kubectl apply -f 01-pod.yaml 
error: error validating "01-pod.yaml": error validating data: [ValidationError(Pod.spec): unknown field "contaiiners" in io.k8s.api.core.v1.PodSpec, ValidationError(Pod.spec): missing required field "containers" in io.k8s.api.core.v1.PodSpec]; if you choose to ignore these errors, turn validation off with --validate=false

image-20250520134417716

图1 报错详情

02 重复创建资源

[root@master01 yaml]# kubectl apply -f 02-network.yaml 
The Pod "likexy" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `spec.activeDeadlineSeconds`, `spec.tolerations` (only additions to existing tolerations) or `spec.terminationGracePeriodSeconds` (allow it to be set to 1 if it was previously negative)core.PodSpec{Volumes:        {{Name: "kube-api-access-cm7wz", VolumeSource: {Projected: &{Sources: {{ServiceAccountToken: &{ExpirationSeconds: 3607, Path: "token"}}, {ConfigMap: &{LocalObjectReference: {Name: "kube-root-ca.crt"}, Items: {{Key: "ca.crt", Path: "ca.crt"}}}}, {DownwardAPI: &{Items: {{Path: "namespace", FieldRef: &{APIVersion: "v1", FieldPath: "metadata.namespace"}}}}}}, DefaultMode: &420}}}},InitContainers: nil,Containers: []core.Container{{
- 			Name:    "b",
+ 			Name:    "aaa",Image:   "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1",Command: nil,... // 4 identical fieldsEnv:          nil,Resources:    {},
- 			VolumeMounts: nil,
+ 			VolumeMounts: []core.VolumeMount{
+ 				{
+ 					Name:      "kube-api-access-cm7wz",
+ 					ReadOnly:  true,
+ 					MountPath: "/var/run/secrets/kubernetes.io/serviceaccount",
+ 				},
+ 			},VolumeDevices: nil,LivenessProbe: nil,... // 10 identical fields},},EphemeralContainers: nil,RestartPolicy:       "Always",... // 5 identical fieldsAutomountServiceAccountToken: nil,NodeName:                     "node03",SecurityContext: &core.PodSecurityContext{
- 		HostNetwork: true,
+ 		HostNetwork: false,HostPID:     false,HostIPC:     false,... // 11 identical fields},ImagePullSecrets: nil,Hostname:         "",... // 16 identical fields}

image-20250520155341241

图2 重复创建名字为likexy的报错
# 解决方案# 删除并重新创建 Pod# 修改Yaml文件

03 容器的镜像名字错误

[root@master01 yaml]# cat 02-network.yaml 
apiVersion: v1
kind: Pod
metadata: name: likeixy
spec:hostNetwork: truecontainers:- name: b# image: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1image: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v100
[root@master01 yaml]# kubectl apply -f 02-network.yaml 
pod/likeixy configured
[root@master01 yaml]# kubectl get pods -o wide
NAME      READY   STATUS             RESTARTS      AGE     IP            NODE     NOMINATED NODE   READINESS GATES
likeixy   0/1     ImagePullBackOff   0 (20s ago)   8m43s   172.2.25.52   node01   <none>           <none>
# 镜像名字错误,导致状态为ImagePullBackOff:镜像拉取失败

image-20250520160931991

图3 镜像名写错了
[root@master01 yaml]# kubectl describe pod likeixy 
Name:         likeixy
Namespace:    default
Priority:     0
Node:         node01/172.2.25.52
Start Time:   Tue, 20 May 2025 16:00:31 +0800
Labels:       <none>
Annotations:  <none>
Status:       Running
IP:           172.2.25.52
IPs:IP:  172.2.25.52
Containers:b:Container ID:   docker://390c2930bab1c54b8275a7889226a73267951fefb78ade253b07cd32f93e1ad9Image:          registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v100Image ID:       docker-pullable://registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps@sha256:3bee216f250cfd2dbda1744d6849e27118845b8f4d55dda3ca3c6c1227cc2e5cPort:           <none>Host Port:      <none>State:          WaitingReason:       ImagePullBackOffLast State:     TerminatedReason:       CompletedExit Code:    0Started:      Tue, 20 May 2025 16:00:32 +0800Finished:     Tue, 20 May 2025 16:08:54 +0800Ready:          FalseRestart Count:  0Environment:    <none>Mounts:/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-k6xv2 (ro)
Conditions:Type              StatusInitialized       True Ready             False ContainersReady   False PodScheduled      True 
Volumes:kube-api-access-k6xv2:Type:                    Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds:  3607ConfigMapName:           kube-root-ca.crtConfigMapOptional:       <nil>DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:Type     Reason     Age                    From               Message----     ------     ----                   ----               -------Normal   Scheduled  14m                    default-scheduler  Successfully assigned default/likeixy to node01Normal   Pulled     14m                    kubelet            Container image "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1" already present on machineNormal   Created    14m                    kubelet            Created container bNormal   Started    14m                    kubelet            Started container bNormal   Killing    5m53s                  kubelet            Container b definition changed, will be restartedNormal   BackOff    5m24s (x2 over 5m52s)  kubelet            Back-off pulling image "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v100"Warning  Failed     5m24s (x2 over 5m52s)  kubelet            Error: ImagePullBackOffNormal   Pulling    4m20s (x4 over 5m53s)  kubelet            Pulling image "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v100"Warning  Failed     4m19s (x4 over 5m53s)  kubelet            Failed to pull image "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v100": rpc error: code = Unknown desc = Error response from daemon: manifest for registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v100 not found: manifest unknown: manifest unknownWarning  Failed     4m19s (x4 over 5m53s)  kubelet            Error: ErrImagePullWarning  BackOff    3m26s (x7 over 5m1s)   kubelet            Back-off restarting failed container

image-20250520161525465

图4 提示镜像拉取失败

04 镜像名字格式不正确

# 这个也是镜像拉取失败,因为定义镜像名称是含有大写字母,所以报错

image-20250520163045672

图5 错误提示,提示图像命名不合法
[root@master01 yaml]# kubectl describe pod likeixy 
Name:         likeixy
Namespace:    default
Priority:     0
Node:         node01/172.2.25.52
Start Time:   Tue, 20 May 2025 16:30:25 +0800
Labels:       <none>
Annotations:  <none>
Status:       Pending
IP:           172.2.25.52
IPs:IP:  172.2.25.52
Containers:b:Container ID:   Image:          registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/Apps:v1Image ID:       Port:           <none>Host Port:      <none>State:          WaitingReason:       InvalidImageNameReady:          FalseRestart Count:  0Environment:    <none>Mounts:/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-dvhcl (ro)
Conditions:Type              StatusInitialized       True Ready             False ContainersReady   False PodScheduled      True 
Volumes:kube-api-access-dvhcl:Type:                    Projected (a volume that contains injected data from multiple sources)TokenExpirationSeconds:  3607ConfigMapName:           kube-root-ca.crtConfigMapOptional:       <nil>DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300snode.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:Type     Reason         Age               From               Message----     ------         ----              ----               -------Normal   Scheduled      72s               default-scheduler  Successfully assigned default/likeixy to node01Warning  InspectFailed  5s (x7 over 71s)  kubelet            Failed to apply default image tag "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/Apps:v1": couldn't parse image reference "registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/Apps:v1": invalid reference format: repository name must be lowercaseWarning  Failed         5s (x7 over 71s)  kubelet            Error: InvalidImageName

image-20250520163223926

图6 提示名字必须是小写字母

05 休眠

[root@master01 yaml]# cat 02-network.yaml 
apiVersion: v1
kind: Pod
metadata:name: oldboyedu-xiuxian-command
spec:hostNetwork: truecontainers:- name: c1image: registry.cn-hangzhou.aliyuncs.com/yinzhengjie-k8s/apps:v1# 修改容器的启动命令,相当于替换了Dockerfile的ENTRYPOINT指令command: ["sleep","3600"]
[root@master01 yaml]# kubectl apply -f 02-network.yaml 
pod/oldboyedu-xiuxian-command created
[root@master01 yaml]# kubectl get pods -o wide
NAME                        READY   STATUS    RESTARTS   AGE   IP            NODE     NOMINATED NODE   READINESS GATES
oldboyedu-xiuxian-command   1/1     Running   0          12s   172.2.25.52   node01   <none>           <none>

image-20250520163741597

图7 表面上容器是正常运行的

image-20250520163833958

图8 使用Curl命令是拒绝连接的
[root@master01 yaml]# kubectl exec -it oldboyedu-xiuxian-command -- sh
/ # ps -ef
PID   USER     TIME  COMMAND1 root      0:00 sleep 36007 root      0:00 sh12 root      0:00 ps -ef
/ # nginx
2025/05/20 08:40:02 [notice] 13#13: using the "epoll" event method
2025/05/20 08:40:02 [notice] 13#13: nginx/1.20.1
2025/05/20 08:40:02 [notice] 13#13: built by gcc 10.2.1 20201203 (Alpine 10.2.1_pre1) 
2025/05/20 08:40:02 [notice] 13#13: OS: Linux 3.10.0-1160.el7.x86_64
2025/05/20 08:40:02 [notice] 13#13: getrlimit(RLIMIT_NOFILE): 4096:4096
2025/05/20 08:40:02 [notice] 14#14: start worker processes
2025/05/20 08:40:02 [notice] 14#14: start worker process 15
2025/05/20 08:40:02 [notice] 14#14: start worker process 16
/ # ps -ef
PID   USER     TIME  COMMAND1 root      0:00 sleep 36007 root      0:00 sh14 root      0:00 nginx: master process nginx15 nginx     0:00 nginx: worker process16 nginx     0:00 nginx: worker process17 root      0:00 ps -ef

image-20250520164105088

图9 进入容器发现有睡眠一小时的启动命令,手动启动Nginx

image-20250520164243937

图10 这回是能够Curl通的

相关文章:

  • P/Invoke 内存资源处理方案
  • Linux bash shell的循环命令for、while和until
  • C++面向对象——多态
  • 单片机复用功能重映射Remap功能
  • 基于单片机的车辆防盗系统设计与实现
  • 第六部分:第三节 - 路由与请求处理:解析顾客的点单细节
  • 【基础知识】SPI协议的种类及异同
  • OpenCV CUDA 模块特征检测与描述------在GPU上执行特征描述符匹配的类cv::cuda::DescriptorMatcher
  • SetThrowSegvLongjmpSEHFilter错误和myFuncInitialize 崩溃
  • 宝塔+fastadmin:给项目添加定时任务
  • 汽车区域电子电气架构(Zonal E/E)的统一
  • CentOS 7上BIND9配置DNS服务器指南
  • SpringSecurity基础入门
  • 使用Mathematica绘制一类矩阵的特征值图像
  • 使用F5-tts复刻音色
  • CVE-2017-4971源码分析与漏洞复现
  • Linux 特权管理与安全——从启用 Root、Sudo 提权到禁用与防护的全景解析
  • idea如何让文件夹分层显示,而不是圆点分割
  • 【牛客-输入输出练习】
  • 安全工具配置
  • 国家话剧院发讣告悼念朱媛媛:始终秉持“戏比天大”的信念
  • 凤阳文旅局回应鼓楼瓦片脱落:鼓楼楼宇系仿古建筑,动工时已履行报批手续
  • 法国参议院调查委员会公布雀巢“巴黎水”丑闻调查报告
  • 金融监管总局将研究出台专门的城市更新项目贷款管理办法:引导大力支持城中村的改造等
  • 国家统计局:4月全国规模以上工业增加值同比增长6.1%
  • 建筑瞭望|从黄浦江畔趸船改造看航运设施的升级与利用