Connecting Kubernetes Services to Deployments
When using Kubernetes services need to be connected to deployments so that all of the pods in the deployment can receive traffic to the services static IP and its port. This requires specific key/value pair matchings in each of these components (service and deployment) configurations. This mapping is known as matching labels with selectors where the declared label for the deployment needs to be selected by the service.
First your deployment configuration you must declare a value for metadata.labels.app
; this value will be used by the service as a way to select the deployment to connect to. Example:
metadata:
name: reporting-db-deployment
labels:
app: reporting-db
Then to map this deployment to a service you would specify it in the services configuration through spec.selector.app
. Example:
spec:
selector:
app: reporting-db
Similar posts:
- How to use a secrets file for postgres credentials using Kubernetes
- When to use which service type in Kubernetes
- Connecting Kubernetes Deployments to Pods
- How to view a Kubernetes pods IP address
- How to view the status data in a Kubernetes Deployment
- Create your first Rails app cluster with Kubernetes and Docker
- Kubernetes kubectl commands for newbies