Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using configmap for ports

Tags:

kubernetes

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
like image 529
Peter Parada Avatar asked Jun 05 '17 13:06

Peter Parada


1 Answers

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.

like image 177
ahmet alp balkan Avatar answered Nov 15 '22 06:11

ahmet alp balkan