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: