映射值错误:无法查明问题根源
P粉828463673
P粉828463673 2023-12-31 20:35:38
0
1
502

这是我的 mysql-deployment.yaml,我试图让它在 kubernetes 上运行,但我收到错误,我已经在我的部署.yml 下面提到了错误

apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql
    tier: database
spec:
  ports:
    - port: 3306
      targetPort: 3306
  selector:
    app: mysql
    tier: database
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels:
    app: mysql
    tier: database
spec:
  accessMode:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
    tier: database
spec:
  selector:
    matchLabels:
      app: mysql
      tier: database
  strategy:
    type: Recreate
  template:
    metadata: 
      labels:
        apps: mysql
        tier: database
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-root-credentials
              key: password
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef::
              name: db-credentials
              key: username
        - name: MYSQL_PASSWORD
          valueFrom:
            secretkeyRef:
              name: db-credentials
              key: password
        - name: MYSQL_DATABASE
          valueFrom:
            configMapKeyRef:
              name: dbbuddyto_mstr_local
              key: name
      ports:
        - containerPort: 3306
          name: mysql
      volumeMounts:
          - name: mysql-persistent-storage
            mountPath: /var/lib/mysql
      volumes:
          - name: mysql-persistent-storage
            PersistentVolumeClaim:
              claimName: mysql-pv-claim

我收到两个错误: 解析 mysql-deployment.yml 时出错:将 YAML 转换为 JSON 时出错:yaml:第 24 行:此上下文中不允许映射值

第二个错误是

来自服务器的错误(BadRequest):创建“mysql-deployment.yml”时出错:版本“v1”中的 PersistentVolumeClaim 无法作为 PersistentVolumeClaim 处理:严格解码错误:未知字段“spec.accessMode”

我正在尝试为 Angular、Spring 和 mysql 构建 Kubernetes 部署。 上述错误是我目前面临的错误。

P粉828463673
P粉828463673

全部回复(1)
P粉748218846

您的 PVC 问题是一个拼写错误。它需要是 spec.accessModes,你错过了最后的 s。

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels:
    app: mysql
    tier: database
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

编辑:

apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql
    tier: database
spec:
  ports:
    - port: 3306
      targetPort: 3306
  selector:
    app: mysql
    tier: database
  clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
  labels:
    app: mysql
    tier: database
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
    tier: database
spec:
  selector:
    matchLabels:
      app: mysql
      tier: database
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        apps: mysql
        tier: database
    spec:
      containers:
        - image: mysql:5.7
          name: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-root-credentials
                  key: password
            - name: MYSQL_USER
              valueFrom:
                secretKeyRef:
                  name: db-credentials
                  key: username
            - name: MYSQL_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-credentials
                  key: password
            - name: MYSQL_DATABASE
              valueFrom:
                configMapKeyRef:
                  name: dbbuddyto_mstr_local
                  key: name
          resources: {}
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          PersistentVolumeClaim:
            claimName: mysql-pv-claim

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板