這是我的 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」
p>
我正在嘗試為 Angular、Spring 和 mysql 建立 Kubernetes 部署。 上述錯誤是我目前面臨的錯誤。
P粉7482188462024-01-01 13:48:22
您的 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