<p>I'm learning SQL Server BDC on minkube using this <strong><a href="https://chrisadkin.io/2018/11/19/kubernetes-for-the-microsoft-data-platform-professional-dipping-your-toe-in-the-water-with-minikube/" rel="nofollow noreferrer">article</a></strong> as a guide. I tried deploying the below yaml file by running the code : <code>kubectl apply -f deployment.yaml</code></p>

<pre><code>apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: mssql-deployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: mssql
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mssql
        image: microsoft/mssql-server-linux
        ports:
        - containerPort: 1433
          securityContext:
          privileged: true
        env:
        - name: ACCEPT_EULA
          value: "Y"
        - name: SA_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mssql
              key: SA_PASSWORD
      volumeMounts:
      - name: mssqldb
        mountPath: /var/opt/mssql
    volumes:
    - name: mssqldb
      persistentVolumeClaim:
        claimName: pvc0001
</code></pre>

<p>It errored due to the v1beta1 APIVersion. I converted this yaml file by running : <code>kubectl convert -f deployment.yaml</code> and got the below script:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: mssql-deployment
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector: null
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: mssql
    spec:
      containers:
      - env:
        - name: ACCEPT_EULA
          value: "Y"
        - name: SA_PASSWORD
          valueFrom:
            secretKeyRef:
              key: SA_PASSWORD
              name: mssql
        image: microsoft/mssql-server-linux
        imagePullPolicy: Always
        name: mssql
        ports:
        - containerPort: 1433
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 10
status: {}
</code></pre>

<p>But when I deploy the above script I get:</p>

<blockquote>
  <p>Error validating "deployment.yaml": error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec; if you choose to ignore these errors, turn validation off with --validate=false</p>
</blockquote>

<p>It is related to matchlabels/matchexpressions but I'm not able to address it. Can someone point me in the right direction?</p>

Gopinath Rajee
<p>You need to add a <code>selector</code> in the spec section of the deployment. It's a mandatory field.The <code>.spec.selector</code> field defines how the Deployment finds which Pods to manage. In this case, you simply select a label that is defined in the Pod template (app: mssql). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.</p>

<pre><code>apiVersion: apps/v1
kindapiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  name: mssql-deployment
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: mssql
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: mssql
    spec:
      containers:
      - env:
        - name: ACCEPT_EULA
          value: "Y"
        - name: SA_PASSWORD
          valueFrom:
            secretKeyRef:
              key: SA_PASSWORD
              name: mssql
        image: microsoft/mssql-server-linux
        imagePullPolicy: Always
        name: mssql
        ports:
        - containerPort: 1433
          protocol: TCP
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 10
status: {}
</code></pre>
