Kubernetes Service Manifest: Difference between revisions
(Created page with "=Internal= * Service Concepts") |
|||
(42 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | |||
* https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#service-v1-core | |||
=Internal= | =Internal= | ||
* [[Kubernetes_Service_Concepts#Service_Manifest|Service Concepts]] | * [[Kubernetes_Service_Concepts#Service_Manifest|Service Concepts]] | ||
=Example= | |||
[[Kubernetes_Manifests#apiVersion|apiVersion]]: v1 | |||
[[Kubernetes_Manifests#kind|kind]]: Service | |||
[[Kubernetes_Manifest_Metadata#Overview|metadata]]: | |||
[[Kubernetes_Manifest_Metadata#name|name]]: blue | |||
[[#labels|labels]]: | |||
size: large | |||
[[Kubernetes_Manifests#spec|spec]]: | |||
[[#type|type]]: ClusterIP|NodePort|LoadBalancer|ExternalName | |||
[[#selector|selector]]: | |||
function: front-end # Label selector, the service is looking for | |||
# pods with the label "function=front-end" | |||
[[#ports|ports]]: | |||
- [[#port|port]]: 80 # Port exposed externally by the service | |||
[[#port_name|name]]: 'http' | |||
[[#targetPort|targetPort]]: 8080 # A container port | |||
[[#nodePort|nodePort]]: 18080 # Only valid for NodePort services | |||
protocol: TCP | |||
[[#sessionAffinity|sessionAffinity]]: Node | |||
[[#publishNotReadyAddresses|publishNotReadyAddresses]]: false | |||
[[#externalTrafficPolicy|externalTrafficPolicy]]: ... | |||
=.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|selector]]. Also see: {{Internal|Kubernetes_Manifest_Metadata#labels|Manifest Metadata - labels}} | |||
=.spec Elements= | |||
==type== | |||
Optional element. If not specified, it is assumed to be "[[Kubernetes Service Concepts#ClusterIP_Service|ClusterIP]]". Other values: "[[Kubernetes_Service_Concepts#NodePort_Service|NodePort]]", "[[Kubernetes_Service_Concepts#LoadBalancer_Service|LoadBalancer]]", "[[Kubernetes_Service_Concepts#ExternalName_Service|ExternalName]]". | |||
==selector== | |||
The service will select the pods to be exposed based on the labels specified in this selector. Also see: {{Internal|Kubernetes_Service_Concepts#Associating_a_Service_with_Pods|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: {{Internal|Kubernetes Service Concepts#Service_Port|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. The port can be specified using an integral value, but also using a name that was declared in the pod's manifest. For more details see: {{Internal|Kubernetes Service Concepts#Service_Target_Port|Service Target Port}} | |||
===<span id='port_name'></span>name=== | |||
When more than one port is configured, each port must carry a name. See:{{Internal|Kubernetes_Service_Concepts#Port_Name|Port Name}} | |||
===nodePort=== | |||
See: {{Internal|Kubernetes_Service_Concepts#NodePort_Service|NodePort Service}} | |||
==sessionAffinity== | |||
By default is "None". The only other possible option is "ClientIP". For more details see: {{Internal|Kubernetes Service Concepts#Session_Affinity|Kubernetes Service Concepts - Session Affinity}} | |||
==publishNotReadyAddresses== | |||
{{Internal|Kubernetes_Container_Probes#publishNotReadyAddress|Container Probes - publishNotReadyAddress}} | |||
==externalTrafficPolicy== | |||
See: {{Internal|Kubernetes_Service_Concepts#Node.2FPod_Relationship|Node/Pod Relationship for NodePort Services}} |
Latest revision as of 00:22, 23 September 2020
External
Internal
Example
apiVersion: v1 kind: Service metadata: name: blue labels: size: large spec: type: ClusterIP|NodePort|LoadBalancer|ExternalName 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 name: 'http' targetPort: 8080 # A container port nodePort: 18080 # Only valid for NodePort services protocol: TCP sessionAffinity: Node publishNotReadyAddresses: false externalTrafficPolicy: ...
.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:
.spec Elements
type
Optional element. If not specified, it is assumed to be "ClusterIP". Other values: "NodePort", "LoadBalancer", "ExternalName".
selector
The service will select the pods to be exposed based on the labels specified in this selector. Also see:
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:
targetPort
The port exposed by the pods associated with the service. The service will forward requests over connections opened with this port as target. The port can be specified using an integral value, but also using a name that was declared in the pod's manifest. For more details see:
name
When more than one port is configured, each port must carry a name. See:
nodePort
See:
sessionAffinity
By default is "None". The only other possible option is "ClientIP". For more details see:
publishNotReadyAddresses
externalTrafficPolicy
See: