My goal is to expose all my ports under one service.
My pod contains a containerised app that runs under port 80.
This is my attempt to create the deployment:
apiVersion: apps/v1
kind: Deployment
metadata: name: my-deployment
spec:
replicas: 5
selector:
matchLabels:
app: myapp
template:
metadata:
name: my-pod
labels:
app: myapp
spec:
containers:
- name: httd
image: httpd
imagePullPolicy: Always
ports:
- containerPort: 80
However, I am getting error:
error: error parsing deployment.yaml: error converting YAML to JSON: yaml: line 3: mapping values are not allowed in this context
The error was in my deployment file: and after fixing it, I could create both the deployment and the service, but the service is still not exposed on the node. Here is my service definition:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: front-end
ports:
- port: 77
targetPort: 80
nodePort: 32766
type: NodePort
As you can see, I am mapping the port 80 in the pod to port 32766 on the node, and when calling: localhost:32766 it returns 404
What did I miss?
This is what the browser shows:
I guess the problem is in your selector section of service.yaml file try this
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: myapp
ports:
- port: 77
targetPort: 80
nodePort: 32766
type: NodePort
In addition to what @shubam_asati posted, your service yaml has port: 77
and targetPort: 80
. But your deployment container is port is 80
. Change port
value to the same value as targetPort
(ie 80
) and you should be able to connect to the app at localhost:<nodePort>
.
when calling: localhost:32766 it returns 404
this means that the app is actually responding to the request. But you sent the request for an URL that the app has not implemented. 404 Not Found
is an Http status code that web servers respond when they don't have a path for the requested URL.