OpenShift Service Definition
External
Internal
Example
apiVersion: v1 kind: Service metadata: annotations: description: The Gogs server's http port labels: app: gogs name: gogs spec: type: ClusterIP ports: - name: web port: 3000 protocol: TCP targetPort: 3000 selector: pod_selector_label_name_1: pod_selector_value_1 pod_selector_label_name_2: pod_selector_value_2 sessionAffinity: None
Elements
spec
selector
If this selector is included in the service's definition, the EndpointsController associates this service with the endpoints of pods that match the selector. The labels are applied to pods by the deployment configuration 'spec.template.metadata.labels'.
ports
The list of ports that are exposed by this service.
port
The port that will be exposed by this service. This is part of the service's address, and it should be used by the service's clients to connect to it. This is not the backend pod's port - though it can have the same value as the backend pod's port.
targetPort
The backend pod's port number or name. This port will be used by the service to access the pod targeted by it. The number must be in the range 1 - 65535. The name must be a IANA_SVC_NAME. If this is a string, it will be looked up as a named port in the target Pod's container ports. If this is not specified, the value of the 'port' field is used (an identity map). The field is ignored for services with clusterIP=None, and should be omitted or set equal to the 'port' field.