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; this value will be used by the service as a way to select the deployment to connect to. Example:

  name: reporting-db-deployment
    app: reporting-db

Then to map this deployment to a service you would specify it in the services configuration through Example:

    app: reporting-db

Similar posts: