简体   繁体   English

mysql 服务挂起在 kubernetes

[英]mysql service pending in kubernetes

I created.yaml file to create mysql service on kubernetes for my internal application, but it's unreachable.我创建了.yaml 文件以在 kubernetes 上为我的内部应用程序创建 mysql 服务,但它无法访问。 I can reach application and also phpmyadmin to reach database but it's not working properly.我可以访问应用程序,也可以访问 phpmyadmin 访问数据库,但它无法正常工作。 I'm stuck with pending status on mysql pod.我在 mysql 吊舱上处于挂起状态。

.yaml file: .yaml 文件:

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 get all output is: kubectl get all output 是:

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

I already did docker pull mysql.我已经做了 docker 拉 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

you are missing the volume to attach with the pod or deployment.您缺少要与 pod 或部署附加的卷。 PVC is required as your deployment configuration is using it. PVC 是必需的,因为您的部署配置正在使用它。

you can see clearly: persistentvolumeclaim "mysql-pv-claim" not found你可以清楚地看到:persistentvolumeclaim "mysql-pv-claim" not found

you can apply below YAML and try.您可以在下面申请 YAML 并尝试。

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

As the error in the message clearly shows persistentvolumeclaim "mysql-pv-claim" not found .由于消息中的错误清楚地显示了persistentvolumeclaim "mysql-pv-claim" not found So you need to provision a persistentvolumeclaim (PVC).因此,您需要提供一个persistentvolumeclaim (PVC)。

There is a static & dynamic provisioning but I'll explain static provisioning here as it will be relatively easy for you to understand & setup.有一个static 和动态配置,但我将在此处解释 static 配置,因为它对您来说相对容易理解和设置。 You need to create a PersistentVolume (PV) which the PVC will use.您需要创建 PVC 将使用的PersistentVolume (PV)。 There are various types of Volumes, about which you read here .有多种类型的卷,您可以在此处阅读。

Which type of Volume you would wanna create would be your choice depending on your environment and needs.您想要创建哪种类型的卷将是您的选择,具体取决于您的环境和需求。 A simple example would be of volume type hostPath .一个简单的例子是卷类型hostPath

Create a PV:创建一个 PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  namespace: cust
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    # The configuration here specifies that the volume is at /tmp/data on the cluster's Node
    path: "/tmp/data"

And then create a PVC:然后创建一个 PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  namespace: cust
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  volumeName: mysql-pv-volume

Once the PVC is successfully created, your deployment shall go through.成功创建 PVC 后,您的部署应通过 go。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM