meerkat
meerkat

Reputation: 3003

Using configmap for ports

Is it possible to use configMap values for port values like containerPort or targetPort?

Here's the possible example how it could work:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: auth
spec:
  template:
    metadata:
        labels:
          app: auth
    spec:
      containers:
        - name: auth
          image: {{someImage}}
          ports:
            - name: CONTAINER_PORT
              containerPort:
                valueFrom:
                  configMapKeyRef:
                    name: auth-config
                    key: PORT
          env:
            - name: PORT
              valueFrom:
                configMapKeyRef:
                  name: auth-config
                  key: PORT

Upvotes: 11

Views: 4222

Answers (1)

ahmet alp balkan
ahmet alp balkan

Reputation: 45302

No, it is not possible for the ports section.

You can use env keys in container's commands and args. Find more here: https://github.com/kubernetes/community/blob/master/contributors/design-proposals/expansion.md

Usually most docker images have static port numbers encoded in the image with EXPOSE keyword, so having a dynamically configurable port is not a best practice from configuration standpoint. Try sticking to fixed port numbers as you can always remap them while exposing the port on Service.

Upvotes: 11

Related Questions