Home > other >  How to use Argo CD to pass environment variables to deploy in kubernetes
How to use Argo CD to pass environment variables to deploy in kubernetes

Time:02-19

We are using argo cd and kubernetes.

And I want to use environmental variables in the yaml file.

For example,

apiVersion: v1
kind: Service
metadata:
  name: guestbook-ui
  annotations:
spec:
  ports:
    - port: $PORT
      targetPort: $TARGET_PORT
  selector:
    app: guestbook-ui

I want to set the value of the environmental variable (PORT and TARGET_PORT) when deploying it to Argo CD.

What should I do?

CodePudding user response:

I'd recommend converting your raw YAML to a Helm chart and templating the relevant fields.

Argo CD has an example Helm app with a service similar to yours.

You could define a service like this:

apiVersion: v1
kind: Service
metadata:
  name: guestbook-ui
  annotations:
spec:
  ports:
    - port: {{ .Values.service.port }}
      targetPort: {{ .Values.service.targetPort }}
  selector:
    app: guestbook-ui

And then define your port and targetPort parameters in Argo CD.

  • Related