k8s创建mysql故障案例No resources found in default namespace.

描述:

我使用StatefulSet创建mysql时,发现找不到pod,具体过程如下:

[root@node1 ~]# kubectl apply -f mysql.yaml 
service/mysql57-svc created
statefulset.apps/mysql57-pod created
[root@node1 ~]# kubectl get pod
No resources found in default namespace.  

排查过程:

发现有一个名称太长了,超过15位了

#1查看statefulset
[root@node1 ~]# kubectl get statefulset
NAME          READY   AGE
mysql57-pod   0/1     24s
#2查看详情
[root@node1 ~]#  kubectl describe statefulset mysql57-pod
Name:               mysql57-pod
Namespace:          default
CreationTimestamp:  Sun, 17 Apr 2022 16:10:36 +0800
Selector:           app=my-sql57
Labels:             <none>
Annotations:        <none>
Replicas:           1 desired | 0 total
Update Strategy:    RollingUpdate
  Partition:        0
Pods Status:        0 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=my-sql57
  Containers:
   mysql57-container:
    Image:      registry.cn-beijing.aliyuncs.com/qingfeng666/mysql:5.7
    Port:       3306/TCP
    Host Port:  0/TCP
    Environment:
      MYSQL_ROOT_PASSWORD:  password
    Mounts:
      /var/lib/mysql from host-path (rw)
  Volumes:
   host-path:
    Type:          HostPath (bare host directory volume)
    Path:          /tmp/mysql
    HostPathType:  DirectoryOrCreate
Volume Claims:     <none>
Events:
  Type     Reason        Age                     From                    Message
  ----     ------        ----                    ----                    -------
  Warning  FailedCreate  3m48s (x17 over 9m16s)  statefulset-controller  create Pod mysql57-pod-0 in StatefulSet mysql57-pod failed error: Pod "mysql57-pod-0" is invalid: spec.containers[0].ports[0].name: Invalid value: "mysql57-container-portname": must be no more than 15 characters

解决:

把spec.tempalet.spec.containers.port.name长名字改掉

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql57-pod
spec:
  selector:
    matchLabels:
      app: my-sql57
  serviceName: mysql57-svc
  replicas: 1
  template:
    metadata:
      labels:
        app: my-sql57
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mysql57-container
        image: registry.cn-beijing.aliyuncs.com/qingfeng666/mysql:5.7
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3306
          name: sql57-portname

再次运行

[root@node1 ~]# kubectl apply -f mysql.yaml 
service/mysql57-svc created
statefulset.apps/mysql57-pod created
[root@node1 ~]# kubectl get pod
NAME            READY   STATUS    RESTARTS   AGE
mysql57-pod-0   1/1     Running   0          15s

 

posted @ 2022-04-17 16:35  linuxTang  阅读(2084)  评论(0编辑  收藏  举报