unable to recognize "deployment.yml": yaml: line 3: mapping values are not allowed in this context

9/22/2019

I have setup a gitlab CI/CD pipeline, which builds and deploys docker images to kubernetes. I'm using yaml based deployment to kubernetes. When i run the pipeline the gitlab-runner always throws "unable to recognize yaml line 3: mapping values are not allowed in this context", but when i run it directly using kubectl create -f deployment.yaml, it runs correctly.

Here's my first few lines of the yml file. I have already validated the yml formatting. The error is thrown at line 3.

apiVersion: v1
kind: Service
metadata:
  labels:
    app: configserver
  name: configserver
spec:
  ports:
  - name: http
    port: 8888
  selector:
    app: configserver

---

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: configserver
  name: configserver
spec:
  replicas: 1
  selector:
    matchLabels:
      app: configserver
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: configserver
    spec:
      containers:
      - image: config-server:latest
        name: configserver
        ports:
        - containerPort: 8888
        resources: {}
      restartPolicy: Always

It this something to do with gitlab?

Thanks.

EDIT:

Here's the relevant part of my .gitlab-ci.yml

stages:
  - build
  - deploy

build:
  stage: build
  script:
    - mvn clean install -DskipTests
    - docker-compose -f docker-compose-istio.yml build
    - docker-compose -f docker-compose-istio.yml push

deploy:
  stage: deploy
  script:
    - kubectl apply -f itp-ms-deploy.yml
    - kubectl apply -f itp-ms-gateway.yml
    - kubectl apply -f itp-ms-autoscale.yml
  when: manual
  only:
    - master
-- Nikhil Harsoor
gitlab-ci
gitlab-ci-runner
kubectl
kubernetes
yaml

0 Answers