OpenShift Service Definition: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(23 intermediate revisions by the same user not shown)
Line 1: Line 1:
=External=
=External=


* https://docs.openshift.com/container-platform/latest/rest_api/kubernetes_v1.html#v1-service
* https://docs.openshift.com/container-platform/latest/rest_api/api/v1.Service.html


=Internal=
=Internal=


* [[OpenShift Service Concepts#Overview|OpenShift Service Concepts]]
* [[OpenShift_Configuration#Definitions|OpenShift Definitions]]
* [[OpenShift_Configuration#Definitions|OpenShift Definitions]]
=Example=
apiVersion: v1
kind: Service
metadata:
  annotations:
    description: The Gogs server's http port
  labels:
    app: gogs
  name: gogs
'''spec''':
  '''type''': <font color=SandyBrown>ClusterIP</font>
  '''[[#ports|ports]]''':
  - name: web
    '''[[#port|port]]''': <font color=SandyBrown>3000</font>
    protocol: TCP
    '''[[#targetPort|targetPort]]''': <font color=SandyBrown>3000</font>
  '''<span id='spec.selector'></span>selector''':
    <font color=SandyBrown>pod_selector_label_name_1</font>: <font color=SandyBrown> pod_selector_value_1</font>
    <font color=SandyBrown>pod_selector_label_name_2</font>: <font color=SandyBrown> pod_selector_value_2</font>
  sessionAffinity: None
=Elements=
==spec==
===selector===
If this selector is included in the service's definition, the [[OpenShift Service Concepts#EndpointsController|EndpointsController]] associates this service with the [[OpenShift_Service_Concepts#Service_Endpoints|endpoints]] of pods that match the selector. The labels are applied to pods by the deployment configuration '[[OpenShift_DeploymentConfig_Definition#labels|spec.template.metadata.labels]]'.
===ports===
The list of [[OpenShift_Service_Concepts#Ports|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 [[#targetPort|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.

Latest revision as of 23:10, 26 February 2018

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.