cancel
Showing results for 
Search instead for 
Did you mean: 
VictoriaSexmer1
Flight Engineer
Flight Engineer
  • 335 Views

Expose a service on 2 ports (http y https)

Hi, I´d like run a service on http and https route, but I´m not sure how to do it. I know I can indicate the port:

oc expose svc --port=8080

But just one port.

How can I expose the service on 2 ports?

Thanks!!!

4 Replies
Chetan_Tiwary_
Community Manager
Community Manager
  • 298 Views

Chetan_Tiwary_
Community Manager
Community Manager
  • 294 Views

One more example with nginx :

apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  type: NodePort
  ports:
  - port: 8080
    targetPort: 80
    protocol: TCP
    name: http
  - port: 443
    protocol: TCP
    name: https
  selector:
    run: my-nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 1
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      volumes:
      - name: secret-volume
        secret:
          secretName: nginxsecret
      - name: configmap-volume
        configMap:
          name: nginxconfigmap
      containers:
      - name: nginxhttps
        image: bprashanth/nginxhttps:1.0
        ports:
        - containerPort: 443
        - containerPort: 80
        volumeMounts:
        - mountPath: /etc/nginx/ssl
          name: secret-volume
        - mountPath: /etc/nginx/conf.d
          name: configmap-volume
0 Kudos
VictoriaSexmer1
Flight Engineer
Flight Engineer
  • 287 Views

Thanks for your answer. I edited my service and add the new port just like your example, and now the application only runs with https. Do you know why?

 

 

eemarins
Mission Specialist
Mission Specialist
  • 257 Views

Services with multiple targetPort needs routes with distinct names. 

Router for http

http-mywebsite.mydomain.com

Router for https

https-mywebsite.mydomain.com

Then, you need to specify the correct port when creating the routes.

Join the discussion
You must log in to join this conversation.