1 个 pod 在 Minikube 上具有未绑定的即时 PersistentVolumeClaims [英] 1 pod has unbound immediate PersistentVolumeClaims on Minikube

查看:97
本文介绍了1 个 pod 在 Minikube 上具有未绑定的即时 PersistentVolumeClaims的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 kubernetes 与 Spring Boot 应用程序一起使用并使用 mysql.但是我在 minikube 仪表板上发现了这个错误:

I'm trying to use kubernetes with a spring boot application and use mysql. But i found this error on minikube dashboard:

0/1 nodes are available: 1 pod has unbound immediate PersistentVolumeClaims.Back-off restarting failed container    

为boath 用户和管理员创建了一个秘密文件,一个configMap 文件也用于将spring boot 映像映射到mysql 的服务.Mysql部署文件为:

A secret file is created for boath user and admin and a configMap file also to map the spring boot image to the service of mysql. Mysql deployement file is:

apiVersion: v1
kind: Service
metadata:
  name: mysql  # DNS name
  labels:
    app: mysql
    tier: database
spec:
  ports:
    - port: 3306
      targetPort: 3306
  selector:       # mysql Pod Should contain same labels
    app: mysql
    tier: database
  clusterIP: None  # We Use DNS, Thus ClusterIP is not relevant
---
# Define a 'Persistent Volume Claim'(PVC) for Mysql Storage, dynamically provisioned by cluster
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim # name of PVC essential for identifying the storage data
  labels:
    app: mysql
    tier: database
spec:
  accessModes:
    - ReadWriteOnce   #This specifies the mode of the claim that we are trying to create.
  resources:
    requests:
      storage: 1Gi    #This will tell kubernetes about the amount of space we are trying to claim.
---
# Configure 'Deployment' of mysql server
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
    tier: database
spec:
  selector: # mysql Pod Should contain same labels
    matchLabels:
      app: mysql
      tier: database
  strategy:
    type: Recreate
  template:
    metadata:
      labels: # Must match 'Service' and 'Deployment' selectors
        app: mysql
        tier: database
    spec:
      containers:
        - image: mysql:latest # image from docker-hub
          args:
            - "--ignore-db-dir=lost+found" # Workaround for https://github.com/docker-library/mysql/issues/186
          name: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD # Setting Root Password of mysql From a 'Secret'
              valueFrom:
                secretKeyRef:
                  name: db-admin # Name of the 'Secret'
                  key: password   # 'key' inside the Secret which contains required 'value'
            - name: MYSQL_USER # Setting USER username on mysql From a 'Secret'
              valueFrom:
                secretKeyRef:
                  name: db-user
                  key: username
            - name: MYSQL_PASSWORD # Setting USER Password on mysql From a 'Secret'
              valueFrom:
                secretKeyRef:
                  name: db-user
                  key: password
            - name: MYSQL_DATABASE # Setting Database Name from a 'ConfigMap'
              valueFrom:
                configMapKeyRef:
                  name: db-config
                  key: name
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:        # Mounting volume obtained from Persistent Volume Claim
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql #This is the path in the container on which the mounting will take place.
      volumes:
        - name: mysql-persistent-storage # Obtaining 'volume' from PVC
          persistentVolumeClaim:
            claimName: mysql-pv-claim

我是 kubernetes 的新手,我找不到解决方案.

I'm new with kubernetes and I can't find solution.

推荐答案

您需要创建一个 PV 来满足 PVC.如果您应用以下 PV,它应该可以工作.

You need to create a PV to satisfy the PVC. If you apply the below PV it should work.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

请注意以下几点

  1. 不建议在生产环境中使用 hostPath
  2. 容量 PV和PVC需要匹配
  3. accessModes PV和PVC需要匹配
  1. Usage of hostPath is not recommended in production
  2. capacity of PV and PVC needs to match
  3. accessModes of PV and PVC needs to match

这篇关于1 个 pod 在 Minikube 上具有未绑定的即时 PersistentVolumeClaims的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆