Exposing two ports in Google Container Engine
Pointed out in another answer using kubernetes allows targeting, but also multiple ports:
kubectl expose deployment example --type=LoadBalancer --port 8080,8081 --target-port 80
No, you cannot specify multiple ports in kubectl run
. But you can use kubectl create
to create a replication controller, and specify multiple ports for the container.
https://github.com/kubernetes/examples/blob/master/cassandra/cassandra-statefulset.yaml has an example:
ports:
- containerPort: 7000
name: intra-node
- containerPort: 7001
name: tls-intra-node
- containerPort: 7199
name: jmx
- containerPort: 9042
name: cql
If required through the helm, it can be achieved as:
deployment.yaml
ports:
- containerPort: {{ .Values.containerport1 }}
#name: containerport1
- containerPort: {{ .Values.containerport2 }}
#name: containerport2
- containerPort: {{ .Values.containerport3 }}
#name: containerport3
The service file needs to have a port name else it will give a render error.
service.yaml
ports:
- name: containerport1
protocol: TCP
port: {{ .Values.exposedport1 }}
targetPort: {{ .Values.containerport1 }}
- name: containerport2
protocol: TCP
port: {{ .Values.exposedport2 }}
targetPort: {{ .Values.containerport2 }}
- name: containerport3
protocol: TCP
port: {{ .Values.exposedport3 }}
targetPort: {{ .Values.containerport3 }}
The values can be set using the --set parameter while installing helm chart.
values.yaml
containerport1: 8001
containerport2: 8002
containerport3: 8003
exposedport1: 8004
exposedport2: 8005
exposedport3: 8006