<p>I am trying to create MySQL Database Deployment but I am getting the below error.</p>
<p>Could you please check and help me to fix this issue?</p>
<p><strong>Error Message:</strong>
C:\Users\Azvmadmin15.docker\YAML&gt;kubectl apply -f mysqlpvc.yaml
service/mysql-srv created</p>
<p>Error from server (BadRequest):</p>
<h2>error when creating &quot;mysqlpvc.yaml&quot;: StatefulSet in version &quot;v1&quot; cannot be handled as a StatefulSet: strict decoding error: unknown field &quot;spec.template.spec.ports&quot;,** unknown field &quot;spec.template.spec.volumeMounts&quot;
**</h2>
<p>C:\Users\Azvmadmin15.docker\YAML&gt;kubectl get all
NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/kubernetes   ClusterIP   10.96.0.1               443/TCP    78m
service/mysql-srv    ClusterIP   10.108.13.118           3306/TCP   17m</p>
<p>C:\Users\Azvmadmin15.docker\YAML&gt;kubectl get pv
NAME              CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                    STORAGECLASS   REASON   AGE
mysql-pv-volume   10Gi       RWO            Retain           Bound    default/mysql-pv-claim   manual                  64m</p>
<p>C:\Users\Azvmadmin15.docker\YAML&gt;kubectl get pvc
NAME             STATUS   VOLUME            CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mysql-pv-claim   Bound    mysql-pv-volume   10Gi       RWO            manual         67m</p>
<p>C:\Users\Azvmadmin15.docker\YAML&gt;kubectl get all
NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
service/kubernetes   ClusterIP   10.96.0.1               443/TCP    78m
service/mysql-srv    ClusterIP   10.108.13.118           3306/TCP   17m</p>
<hr />
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>YAML file: 

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql-ss
spec:
  replicas: 1
  selector:
    matchLabels:
      app: "mysql-pod"
  serviceName: "mysql"
  template:
    metadata:
      labels:
        app: "mysql-pod"
    spec:
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: tiger1234
      ports:
      - containerPort: 3306
        name: mysql
      volumeMounts:
      - name: mysql-persistent-storage
        mountPath: /var/lib/mysql

---

apiVersion: v1
kind: Service
metadata:
  name: mysql-srv
spec:
  ports:
  - port: 3306
  selector:
    app: "mysql"</code></pre>
</div>
</div>
</p>

Balaji
<p>You have indentation issues with <code>ports</code> and <code>volumeMounts</code>, below YAML should work</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mysql-ss
spec:
  replicas: 1
  selector:
    matchLabels:
      app: &quot;mysql-pod&quot;
  serviceName: &quot;mysql&quot;
  template:
    metadata:
      labels:
        app: &quot;mysql-pod&quot;
    spec:
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
      containers:
      - image: mysql:5.6
        name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: tiger1234
        ports:
        - containerPort: 3306
          name: mysql

---

apiVersion: v1
kind: Service
metadata:
  name: mysql-srv
spec:
  ports:
  - port: 3306
  selector:
    app: &quot;mysql&quot;
</code></pre>
<p>See the examples in docs for <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-volume-storage/#configure-a-volume-for-a-pod" rel="nofollow noreferrer">volumeMounts</a> and <a href="https://kubernetes.io/docs/concepts/workloads/pods/#using-pods" rel="nofollow noreferrer">ports</a></p>
