1. 程式人生 > 其它 >k8s建立mysql故障案例No resources found in default namespace.

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