<p>I am working on setting up a cloud DevOps deployment pipeline using Gitlab CI online, Kubernetes, and docker. I am following an example post at <a href="https://about.gitlab.com/2016/12/14/continuous-delivery-of-a-spring-boot-application-with-gitlab-ci-and-kubernetes/" rel="nofollow noreferrer">Continous delivery of a spring boot application with Gitlab CI and kubernetes</a> and <a href="https://stackoverflow.com/questions/50015081/kubectl-delete-create-secret-forbidden-google-cloud-platform">Kubectl delete/create secret forbidden (Google cloud platform)</a> . </p>

<p>Find below my .gitlab-ci.yml file's source</p>

<pre><code>image: docker:latest
services:
  - docker:dind

variables:
  DOCKER_DRIVER: overlay
  SPRING_PROFILES_ACTIVE: gitlab-ci

stages:
  - build
  - package
  - deploy

maven-build:
  image: maven:3-jdk-8
  stage: build
  script: "mvn package -B"
  artifacts:
    paths:
      - target/*.jar

docker-build:
  stage: package
  script:
  - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.gitlab.com
  - docker build -t registry.gitlab.com/username/mta-hosting-optimizer .
  - docker push registry.gitlab.com/username/mta-hosting-optimizer

k8s-deploy:
  image: google/cloud-sdk
  stage: deploy
  script:
  - echo "$GOOGLE_KEY" &gt; key.json
  - gcloud auth activate-service-account --key-file key.json
  - gcloud config set compute/zone europe-west1-c
  - gcloud config set project mta-hosting-optimizer
  - gcloud config unset container/use_client_certificate
  - gcloud config set container/use_client_certificate True
  - gcloud container clusters get-credentials mta-hosting-optimizer
  - kubectl create -f admin.yaml --validate=false
  - kubectl create clusterrolebinding serviceaccounts-cluster-admin--clusterrole=cluster-admin --group=system:serviceaccounts
  - kubectl delete secret registry.gitlab.com
  - kubectl create secret docker-registry registry.gitlab.com --docker-server=https://registry.gitlab.com --docker-username=username --docker-password=$REGISTRY_PASSWD --docker-email=email@email.com
  - kubectl apply -f deployment.yml
</code></pre>

<p>Deployment fails at the line below</p>

<pre><code>  - kubectl create -f admin.yaml --validate=false
</code></pre>

<p>The error message displayed upon this failure is as follow:</p>

<pre><code>error: error converting YAML to JSON: yaml: mapping values are not allowed in this context
ERROR: Job failed: exit code 1
</code></pre>

<p>The admin.yaml file's source is as follows:</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: kubernetes-dashboard labels: k8s-app: kubernetes-dashboard roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system
</code></pre>

<p>The Maven build and Docker build/package stages work find. This is the only stage that fails. I will appreciate everyone's help in resolving this issue.
Thank you very much.</p>

sage
<p>You have a YAML validation error. This means that your YAML isn't formatted correctly.</p>

<p><a href="https://i.stack.imgur.com/emBac.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/emBac.png" alt="screenshot"></a></p>

<p>You most likely wanted to format your <code>admin.yaml</code> file this way:</p>

<pre><code>apiVersion: rbac.authorization.k8s.io/v1beta1 
kind: ClusterRoleBinding 
metadata: 
    name: kubernetes-dashboard 
    labels: 
        k8s-app: kubernetes-dashboard
    namespace: kube-system
roleRef: 
  apiGroup: rbac.authorization.k8s.io 
  kind: ClusterRole 
  name: cluster-admin 
subjects: 
- kind: ServiceAccount 
  name: kubernetes-dashboard 
</code></pre>

<hr>

<p><strong>Also:</strong> As Matthew L Daniel already <a href="https://stackoverflow.com/questions/51236932/kubernetes-continuous-deployment-stage-in-gitlab-online-fails#comment89494969_51236932">pointed out</a> you shouldn't disable validation of the YAML files.</p>
