Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda