<p>I've the GitLab ci/cd yaml file script</p>
<pre><code>services:
  - docker:19.03.11-dind
workflow:
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == &quot;developer&quot; || $CI_COMMIT_BRANCH == &quot;stage&quot;|| ($CI_COMMIT_BRANCH =~ (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?)+/i))
      when: always
    - if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH != &quot;developer&quot; || $CI_COMMIT_BRANCH != &quot;stage&quot;|| ($CI_COMMIT_BRANCH !~ (/^([A-Z]([0-9][-_])?)?SPRINT(([-_][A-Z][0-9])?)+/i))
      when: never 
stages:
  - build
  - Publish
  - deploy
cache:
  paths:
    - .m2/repository
    - target
build_jar:
  image: maven:3.8.3-jdk-11
  stage: build
  script: 
    - mvn clean install package -DskipTests=true
  artifacts:
    paths:
      - target/*.jar
docker_build:
  stage: Publish
  image: docker:19.03.11
  services:
    - docker:19.03.11-dind
  variables:
    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
  script: 
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
deploy_dev:
  stage: deploy
  image: stellacenter/aws-helm-kubectl
  before_script:
    - aws configure set aws_access_key_id ${DEV_AWS_ACCESS_KEY_ID}
    - aws configure set aws_secret_access_key ${DEV_AWS_SECRET_ACCESS_KEY}
    - aws configure set region ${DEV_AWS_DEFAULT_REGION}
  script:
    - sed -i &quot;s/&lt;VERSION&gt;/${CI_COMMIT_SHORT_SHA}/g&quot; provider-service-dev.yml    
    - mkdir -p  $HOME/.kube
    - cp $KUBE_CONFIG_DEV $HOME/.kube/config
    - chown $(id -u):$(id -g) $HOME/.kube/config 
    - export KUBECONFIG=$HOME/.kube/config
    - kubectl apply -f provider-service-dev.yml
  only:
    - developer 
deploy_stage:
  stage: deploy
  image: stellacenter/aws-helm-kubectl
  before_script:
    - aws configure set aws_access_key_id ${DEV_AWS_ACCESS_KEY_ID}
    - aws configure set aws_secret_access_key ${DEV_AWS_SECRET_ACCESS_KEY}
    - aws configure set region ${DEV_AWS_DEFAULT_REGION}
  script:
    - sed -i &quot;s/&lt;VERSION&gt;/${CI_COMMIT_SHORT_SHA}/g&quot; provider-service-stage.yml    
    - mkdir -p  $HOME/.kube
    - cp $KUBE_CONFIG_STAGE $HOME/.kube/config
    - chown $(id -u):$(id -g) $HOME/.kube/config 
    - export KUBECONFIG=$HOME/.kube/config
    - kubectl apply -f provider-service-stage.yml
  only:
    - stage    
</code></pre>
<p>this yaml script which I combine from two branches i.e developer and stage
but I'm having two yml files for separate branches (for developer and stage)</p>
<p>provider-service-dev.yml</p>
<pre><code>   apiVersion: apps/v1
kind: Deployment
metadata:
  name: provider-app
  namespace: stellacenter-dev
  labels:
    app: provider-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app : provider-app
  template:
    metadata:
      labels:
        app: provider-app
    spec:
      containers:
      - name: provider-app
        image: registry.gitlab.com/stella-center/backend-services/provider-service:&lt;VERSION&gt;
        imagePullPolicy: Always
        ports:
          - containerPort: 8092
      imagePullSecrets:
        - name:  gitlab-registry-token-auth

---

apiVersion: v1
kind: Service
metadata:
  name:  provider-service
  namespace: stellacenter-dev
spec:
  type: NodePort
  selector:
    app:  provider-app
  ports:
  - port:  8092
    targetPort:  8092
</code></pre>
<p>provider-service-stage.yml</p>
<pre><code>   apiVersion: apps/v1
kind: Deployment
metadata:
  name: provider-app
  namespace: stellacenter-stage-uat
  labels:
    app: provider-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app : provider-app
  template:
    metadata:
      labels:
        app: provider-app
    spec:
      containers:
      - name: provider-app
        image: registry.gitlab.com/stella-center/backend-services/provider-service:&lt;VERSION&gt;
        imagePullPolicy: Always
        ports:
          - containerPort: 8092
      imagePullSecrets:
        - name:  gitlab-registry-token-auth

---

apiVersion: v1
kind: Service
metadata:
  name:  provider-service
  namespace: stellacenter-stage-uat
spec:
  type: NodePort
  selector:
    app:  provider-app
  ports:
  - port:  8092
    targetPort:  8092
</code></pre>
<p>I have separately mentioned in the gitlab cicd yaml script but it shows the error like</p>
<pre><code>$ kubectl apply -f provider-service-dev.yml
Error from server (NotFound): error when creating &quot;provider-service-dev.yml&quot;: namespaces &quot;stellacenter-dev&quot; not found
Error from server (NotFound): error when creating &quot;provider-service-dev.yml&quot;: namespaces &quot;stellacenter-dev&quot; not found
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1 
</code></pre>
<p>It shows error in the last line of the script. It shows that the namespaces can't found but that was there only . I don't know how to sort it out this. Please Kindly help me to sort it out</p>

Cyril I
<p>The error is saying your namespace is missing. You must first <a href="https://kubernetes.io/docs/tasks/administer-cluster/namespaces-walkthrough/#create-new-namespaces" rel="nofollow noreferrer">create the namespace</a> <code>stellacenter-dev</code>.</p>
