Kubernetes Service Manifest: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 50: Line 50:
===name===
===name===


When more than one port is configured, each port must carry a name. See [[Kubernetes_Service_Concepts#Service_Port.28s.29|Service Port]].
When more than one port is configured, each port must carry a name. See {{Internal|Kubernetes_Service_Concepts#Service_Port.28s.29|Service Port}}


==sessionAffinity==
==sessionAffinity==

Revision as of 03:11, 20 September 2020

External

Internal

Example

apiVersion: v1
kind: Service
metadata:
  name: blue
  labels:
    size: large
spec:
  type: ClusterIP
  selector:
    function: front-end # Label selector, the service is looking for
                        # pods with the label "function=front-end"
  ports:
  - port: 80            # Port exposed externally by the service
    targetPort: 8080    # A container port    
    protocol: TCP
  sessionAffinity: Node

.metadata Elements

labels

The labels declared here apply to the service instance itself, they have no relationship to the target pods' labels, which are declared in the spec selector. Also see:

Manifest Metadata - labels

.spec Elements

type

Optional element. If not specified, it is assumed to be "ClusterIP".

selector

The service will select the pods to be exposed based on the labels specified in this selector. Also see:

Service Concepts - Associating a Service with Pods

ports

The element contains an array of ports that will exposed by the service. A port is specified by the following elements:

port

The port exposed by the service externally. This is the port the service will be available on, and the value will be used by the external clients connecting to the service. Also see:

Service Port

targetPort

The port exposed by the pods associated with the service. The service will forward requests over connections opened with this port as target. Also see:

Service Target Port

name

When more than one port is configured, each port must carry a name. See

Service Port

sessionAffinity

By default is "None". The only other possible option is "ClientIP". For more details see:

Kubernetes Service Concepts - Session Affinity

publishNotReadyAddresses