Add example of Service targetPort binding by name
Add example of Service targetPort binding by name
This commit is contained in:
committed by
GitHub
parent
670ae1a6de
commit
d78f8d2736
@@ -109,12 +109,45 @@ field.
|
|||||||
{{< /note >}}
|
{{< /note >}}
|
||||||
|
|
||||||
Port definitions in Pods have names, and you can reference these names in the
|
Port definitions in Pods have names, and you can reference these names in the
|
||||||
`targetPort` attribute of a Service. This works even if there is a mixture
|
`targetPort` attribute of a Service. For example, we can bind the `targetPort`
|
||||||
of Pods in the Service using a single configured name, with the same network
|
of the Service to the Pod port in the following way:
|
||||||
protocol available via different port numbers.
|
|
||||||
This offers a lot of flexibility for deploying and evolving your Services.
|
```yaml
|
||||||
For example, you can change the port numbers that Pods expose in the next
|
apiVersion: v1
|
||||||
version of your backend software, without breaking clients.
|
kind: Pod
|
||||||
|
metadata:
|
||||||
|
name: nginx
|
||||||
|
labels:
|
||||||
|
app.kubernetes.io/name: proxy
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: nginx:11.14.2
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
name: http-web-service
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: nginx-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app.kubernetes.io/name: proxy
|
||||||
|
ports:
|
||||||
|
- name: name-of-service-port
|
||||||
|
protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: http-web-service
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
This works even if there is a mixture of Pods in the Service using a single
|
||||||
|
configured name, with the same network protocol available via different
|
||||||
|
port numbers. This offers a lot of flexibility for deploying and evolving
|
||||||
|
your Services. For example, you can change the port numbers that Pods expose
|
||||||
|
in the next version of your backend software, without breaking clients.
|
||||||
|
|
||||||
The default protocol for Services is TCP; you can also use any other
|
The default protocol for Services is TCP; you can also use any other
|
||||||
[supported protocol](#protocol-support).
|
[supported protocol](#protocol-support).
|
||||||
|
|||||||
Reference in New Issue
Block a user