Connecting Kubernetes Deployments to Pods
When using Kubernetes pods need to be connected to deployments so the deployment knows which pods it is responsible for. This requires specific key/value pair mappings in your K8’s deployment configuration. This mapping is known as matching labels with selectors where the declared label for the pod(s) needs to be selected by the deployment.
First to declare the pods label add a value in the deployment configuration for the path spec.template.metadata.labels.app
. Example:
spec:
template:
metadata:
labels:
app: reporting-db
Then to map the pod(s) to the deployment using a selector you would specify a value in the deployments configuration for spec.selector.matchLabels.app
. Example:
spec:
selector:
matchLabels:
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 Services to Deployments
- 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