TIS0701 - Deployment Exposing the Same Port as the Service Not Found
A Deployment exposing the same port as the Service is not found.
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
-
Service and Deployment Port Mismatch
Service:
apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: example-namespace
spec:
ports:
- port: 80
targetPort: 8080Deployment:
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: 9090Explanation: The
Serviceis configured to target port8080in the workload, but theDeploymentexposes port9090. 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.
-
Update Deployment to Match the Service Port
Update the
Deploymentto expose the correct port that matches theServicedefinition.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: 8080Explanation: By updating the
containerPortto8080, theDeploymentnow matches thetargetPortdefined in theService, allowing traffic to be correctly routed from the service to the workload.