Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

264
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda