Hi experts,
I'm running DO280 class this week, and got the question about p81 YAML file from a student.
---------------
kind: Route
...
...
spec:
host: quotapp.apps.lab.example.com
port:
targetPort: 8080-tcp <----
...
He wants to know the reason why the targetPort attribute is written in the file: Is it nessessary?
And I'd like to understand the difference between "port" and "targetPort" attribute in difinition of Router/Service also.
Does anyone know answer?
Thanks in advance.
Yasufumi
In the context of an OpenShift Service, targetPort is the mapping of the service traffic to the port inside the container. So for example, you might have a service that maps from port 80 on the service/route to port 8080 inside the container. In that case, a snip of your YAML file might look something like this:
apiVersion: v1 kind: Service ... spec: ... ports: - name: web port: 80 protocol: TCP targetPort: 8080 ...
A route simply exposes a service at a host name, like www.example.com, so that external clients can reach it by name, and you can reference a specific service port mapping to expose like this, where web is the name of the port mapping defined in the service:
apiVersion: route.openshift.io/v1 kind: Route ... spec: host: mywebapp.apps.openshift.com port: targetPort: web to: kind: Service name: frontend weight: 100
Specifically for the targetPort attribute on a route object's YAML, the OpenShift Route Object Schema defines the attribute as:
(intstr.IntOrString) The target port on pods selected by the service this route points to. If this is a string, it will be looked up as a named port in the target endpoints port list. Required
So it is just how you define what pod port to target via your route.
References:
In the context of an OpenShift Service, targetPort is the mapping of the service traffic to the port inside the container. So for example, you might have a service that maps from port 80 on the service/route to port 8080 inside the container. In that case, a snip of your YAML file might look something like this:
apiVersion: v1 kind: Service ... spec: ... ports: - name: web port: 80 protocol: TCP targetPort: 8080 ...
A route simply exposes a service at a host name, like www.example.com, so that external clients can reach it by name, and you can reference a specific service port mapping to expose like this, where web is the name of the port mapping defined in the service:
apiVersion: route.openshift.io/v1 kind: Route ... spec: host: mywebapp.apps.openshift.com port: targetPort: web to: kind: Service name: frontend weight: 100
Specifically for the targetPort attribute on a route object's YAML, the OpenShift Route Object Schema defines the attribute as:
(intstr.IntOrString) The target port on pods selected by the service this route points to. If this is a string, it will be looked up as a named port in the target endpoints port list. Required
So it is just how you define what pod port to target via your route.
References:
Thanks beelandc-san,
I've now totaly clarified and I will answer for the student's question!
yasufumic
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.