错误:解析wordpress-deployment.yaml时出错:将YAML转换为JSON时出错:yaml:第33行:找不到预期的':'

时间:2020-10-21 07:31:49

标签: wordpress kubernetes yaml

  1. 尝试遵循kubernetes教程[1]示例:使用持久卷部署WordPress和MySQL;
  2. 使用cloudshell在Google kubernetes上运行命令“ kubectl apply -f wordpress-deployment.yaml”;
  3. 得到此错误:解析wordpress-deployment.yaml时出错:将YAML转换为JSON时出错:yaml:第33行:找不到预期的':'

[{1] https://kubernetes.io/docs/tutorials/stateful-application/mysql-wordpress-persistent-volume/

/ ** 更新:谢谢!我决定为wordpress docker开发环境使用一键设置 https://console.cloud.google.com/marketplace/details/google/wordpress ** /

wordpress-deployment.yaml

apiVersion: v1
kind: Service
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  ports:
    - port: 80
  selector:
    app: wordpress
    tier: frontend
  type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: wp-pv-claim
  labels:
    app: wordpress
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
spec:
  selector:
    matchLabels:
      app: wordpress
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wordpress
        tier: frontend
    spec:
      containers:
      - image: wordpress:4.8-apache
        name: wordpress
        env:
        - name: WORDPRESS_DB_HOST
          value: 34.72.250.151
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        - name: WORDPRESS_DB_USER
          valueFrom:
           secretkeyRef:
            name: mysql-pass
        ports:
        - containerPort: 80
          name: wordpress
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wp-pv-claim

2 个答案:

答案 0 :(得分:1)

yaml文件中的以下代码段存在3个问题。

  1. 在以下代码段中,在 valueFrom:键之后有一个空格,请删除“:”之后的空格

  2. 在secretKeyRef键中,“ K”应为大写字母(secretKeyRef)。

  3. secretKeyRef缺少“键”值。

    - name: WORDPRESS_DB_USER
               valueFrom:
                secretkeyRef:
                 name: mysql-pass 
    

应该是这样。

- name: WORDPRESS_DB_USER
          valueFrom:
           secretKeyRef:
            name: mysql-pass
            key: username

谢谢

答案 1 :(得分:0)

为了避免输入错误,我决定为wordpress docker开发环境使用一键设置 https://console.cloud.google.com/marketplace/details/google/wordpress