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!!!
@VictoriaSexmer1 Refer the K8 documentation for the same here : https://kubernetes.io/docs/concepts/services-networking/service/#multi-port-services
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
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?
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.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.