kubernetes中的mysql处于pending状态?

啊啊 发表于: 2021-04-08   最后更新时间: 2021-04-08 15:55:42   2,507 游览

我通过以下.yaml创建了mysql,但是状态一直处于pending

.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  namespace: cust
  labels:
    app: db
spec:
  replicas: 1
  selector:
    matchLabels:
      app: db
  template:
    metadata:
      labels:
        app: db
    spec:
      containers:
      - name: mysql
        image: mysql
        imagePullPolicy: Never
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: flaskapi-cred
              key: db_root_password
        ports:
        - containerPort: 3306
          name: db-container
        volumeMounts:
          - name: mysql-persistent-storage
            mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pv-claim


---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: cust
  labels:
    app: db
spec:
  ports:
  - port: 3306
    protocol: TCP
    name: mysql
  selector:
    app: db
  type: LoadBalancer

kubectl获取的输出如下:

NAME                                         READY   STATUS    RESTARTS   AGE
pod/flaskapi-deployment-59bcb745ff-gl8xn     1/1     Running   0          117s
pod/mysql-99fb77bf4-sbhlj                    0/1     Pending   0          118s
pod/phpmyadmin-deployment-5fc964bf9d-dk59t   1/1     Running   0          118s

NAME                                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/flaskapi-deployment     1/1     1            1           117s
deployment.apps/mysql                   0/1     1            0           118s
deployment.apps/phpmyadmin-deployment   1/1     1            1           118s

我已经做了docker pull mysql

Edit

Name:           mysql-99fb77bf4-sbhlj
Namespace:      z2
Priority:       0
Node:           <none>
Labels:         app=db
                pod-template-hash=99fb77bf4
Annotations:    <none>
Status:         Pending
IP:
IPs:            <none>
Controlled By:  ReplicaSet/mysql-99fb77bf4
Containers:
  mysql:
    Image:      mysql
    Port:       3306/TCP
    Host Port:  0/TCP
    Environment:
      MYSQL_ROOT_PASSWORD:  <set to the key 'db_root_password' in secret 'flaskapi-secrets'>  Optional: false
    Mounts:
      /var/lib/mysql from mysql-persistent-storage (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-gmbnd (ro)
Conditions:
  Type           Status
  PodScheduled   False
Volumes:
  mysql-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  mysql-pv-claim
    ReadOnly:   false
  default-token-gmbnd:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-gmbnd
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason            Age    From               Message
  ----     ------            ----   ----               -------
  Warning  FailedScheduling  3m44s  default-scheduler  persistentvolumeclaim "mysql-pv-claim" not found
  Warning  FailedScheduling  3m44s  default-scheduler  persistentvolumeclaim "mysql-pv-claim" not found
在线,22分钟前登录
发表于 2021-04-08
添加评论

缺少与pod或deployment连接的volume。

错误在这里 : persistentvolumeclaim "mysql-pv-claim" not found

你可以应用下面的YAML来创建PVC

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
你的答案

查看kubernetes相关的其他问题或提一个您自己的问题