Skip to main content
logoTetrate Istio SubscriptionVersion: Next

TIS0701 - Deployment Exposing the Same Port as the Service Not Found

A Deployment exposing the same port as the Service is not found.

Recommendation: Ensure Service and Deployment Ports Match

To ensure proper traffic flow and connectivity between services and workloads, always ensure that the targetPort in the Service matches the containerPort in the corresponding Deployment.

Examples

  1. Service and Deployment Port Mismatch

    Service:

    apiVersion: v1
    kind: Service
    metadata:
    name: my-service
    namespace: example-namespace
    spec:
    ports:
    - port: 80
    targetPort: 8080

    Deployment:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: my-deployment
    namespace: example-namespace
    spec:
    selector:
    matchLabels:
    app: my-app
    template:
    metadata:
    labels:
    app: my-app
    spec:
    containers:
    - name: my-container
    image: my-image
    ports:
    - containerPort: 9090

    Explanation: The Service is configured to target port 8080 in the workload, but the Deployment exposes port 9090. This mismatch means that the service cannot properly route traffic to the intended workload, resulting in failed connections.

Recommendation

Ensure the port definitions in the workload and service definitions match.

  1. Update Deployment to Match the Service Port

    Update the Deployment to expose the correct port that matches the Service definition.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: my-deployment
    namespace: example-namespace
    spec:
    selector:
    matchLabels:
    app: my-app
    template:
    metadata:
    labels:
    app: my-app
    spec:
    containers:
    - name: my-container
    image: my-image
    ports:
    - containerPort: 8080

    Explanation: By updating the containerPort to 8080, the Deployment now matches the targetPort defined in the Service, allowing traffic to be correctly routed from the service to the workload.