title: Gitlab CI - K8s - Deployment
body: <p>just going through this guide on gitlab and k8s <a href="https://about.gitlab.com/2016/12/14/continuous-delivery-of-a-spring-boot-application-with-gitlab-ci-and-kubernetes/" rel="nofollow noreferrer">gitlab-k8s-cd</a>, but my build keeps failing on this part:</p>
  
  <pre><code>- kubectl delete secret registry.gitlab.com
  - kubectl create secret docker-registry registry.gitlab.com --docker-server=https://registry.gitlab.com --docker-username=&lt;my_username&gt; --docker-password=$REGISTRY_PASSWD --docker-email=&lt;my_email&gt;
  </code></pre>
  
  <p>Although I am not entirely sure what password is needed for --docker-password, I have created an API token in gitlab for my user and I am using that in the secure variables. </p>
  
  <p>This is the error:</p>
  
  <pre><code>$ gcloud container clusters get-credentials deployment
  Fetching cluster endpoint and auth data.
  kubeconfig entry generated for deployment.
  $ kubectl delete secret registry.gitlab.com
  Error from server: secrets "registry.gitlab.com" not found
  ERROR: Build failed: exit code 1
  </code></pre>
  
  <p>Any help would be much appreciated thanks.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Since the initial post, by removing the initial <code>kubectl delete secret</code> and re-building worked, so it was failing on deleting when there was no previous secret. </p>
  
  <p><strong>Second Edit</strong></p>
  
  <p>Having problems with my deployment.yml for K8s, could anyone shed any light on why I am getting this error:</p>
  
  <pre><code>error validating "deployment.yml": error validating data: field spec.template.spec.containers[0].ports[0]: expected object of type map[string]interface{},
  </code></pre>
  
  <p>With this yml:</p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: &lt;app&gt;
  spec:
    replicas: 2
    template:
      metadata:
        labels:
          app: &lt;app&gt;
      spec:
        containers:
        - name: deployment
          image: registry.gitlab.com/&lt;username&gt;/&lt;app&gt;
          imagePullPolicy: Always
          ports:
          - "80:8080"
          env:
          - name: PORT
            value: "8080"
        imagePullSecrets:
          - name: registry.gitlab.com
  </code></pre>
  
  <p>And this error:</p>
  
  <pre><code>error validating "deployment.yml": error validating data: found invalid field imagePullSecrets for v1.Container; if you choose to ignore these errors, turn validation off with --validate=false
  </code></pre>
  
  <p>With this yml:</p>
  
  <pre><code>apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: &lt;app&gt;
  spec:
    replicas: 2
    template:
      metadata:
        labels:
          app: &lt;app&gt;
      spec:
        containers:
        - name: &lt;app&gt;
          image: registry.gitlab.com/&lt;project&gt;/&lt;app&gt;
          imagePullPolicy: Always
          ports:
          - "80:8080"
          env:
          - name: PORT
            value: "8080"
        imagePullSecrets:
          - name: registry.gitlab.com
  </code></pre>
  
  <p><strong>Latest YAML</strong></p>
  
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: &lt;app_name&gt;
    labels:
      app: &lt;app_name&gt;
  spec:
    ports:
      - port: 80
    selector:
      app: &lt;app_name&gt;
      tier: frontend
    type: LoadBalancer
  ---
  apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: &lt;app_name&gt;
    labels:
      app: &lt;app_name&gt;
  spec:
    strategy:
      type: Recreate
    template:
      metadata:
        labels:
          app: &lt;app_name&gt;
          tier: frontend
      spec:
        containers:
        - image: registry.gitlab.com/&lt;project&gt;/&lt;app&gt;
          imagePullPolicy: Always
          name: &lt;app_name&gt;
          env:
          - name: PORT
            value: "8080"
          imagePullSecrets:
          - name: registry.gitlab.com
          ports:
            - containerPort: 8080
              hostPort: 80
  </code></pre>