Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
How to Deploy from Gitlab-ci to multiple kubernetes namespaces?

I have two variable containing my namespaces names:

$KUBE_NAMESPACE_DEV ="stellacenter-dev"
$KUBE_NAMESPACE_STAGE "stellacenter-stage-uat" 

Now I want to modify the following .gitlab-ci.yaml configuration to include the namespace logic:

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 "s/<VERSION>/${CI_COMMIT_SHORT_SHA}/g" provider-service.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.yml 
  only:
    - developer  

Provide-service.yml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: provider-app
  namespace: "stellacenter-dev" or "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:<VERSION>
        imagePullPolicy: Always
        ports:
          - containerPort: 8092
      imagePullSecrets:
        - name:  gitlab-registry-token-auth

---

apiVersion: v1
kind: Service
metadata:
  name:  provider-service
  namespace: "stellacenter-dev" "stellacenter-stage-uat" 
spec:
  type: NodePort
  selector:
    app:  provider-app
  ports:
  - port:  8092
    targetPort:  8092

I don't know how to integrate the variables and the values correctly . I'm facing the error while I run pipeline.Kindly help me to sort it out.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can remove the namespace: NAMESPACE from the manifest, and apply the resource in a namespace using the commandline.

- kubectl apply -f ./provider-service.yml -n ${KUBE_NAMESPACE_DEV}
- kubectl apply -f ./provider-service.yml -n ${KUBE_NAMESPACE_STAGE}
about 4 years ago · Juan Pablo Isaza Report

0

Just add one line above the apply command

- export KUBECONFIG=$HOME/.kube/config
- kubectl apply -f ./provider-service.yml 

using sed you can replace the respective variable into YAML file

sed -i "s, NAMESPACE,$KUBE_NAMESPACE_DEV," Provide-service.yml

Inside that YAML file keep it something like

apiVersion: v1
kind: Service
metadata:
  name:  provider-service
  namespace: NAMESPACE
spec:
  type: NodePort

You can keep one variable instead of two for Namespace management however using the sed you can set the Namespace into the YAML and apply that YAML.

While inside your repo it will be like a template, when CI will run NAMESPACE will get replaced by sed command and YAML will get applied to k8s. Accordingly, you can also keep other things as templates and replace them with sed as per need.

    apiVersion: v1
    kind: Service
    metadata:
      name:  SERVICE_NAME
      namespace: NAMESPACE
    spec:
      type: SERVICE_TYPE
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!