I am trying to expose a deployment I made on minikube:
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-test
labels:
app: debian
spec:
replicas: 1
selector:
matchLabels:
app: debian
strategy: {}
template:
metadata:
labels:
app: debian
spec:
containers:
- image: agracia10/debian_bash:latest
name: debian
ports:
- containerPort: 8006
resources: {}
restartPolicy: Always
status: {}
I decided to follow was is written on here
I try to expose the deployment using the following command:
kubectl expose pod deployment-test-8497d6f458-xxhgm --type=NodePort --port=8080 --target-port=80
but when I try to then access the service created by the expose command, using the url provided by
minikube service deployment-test-8497d6f458-xxhgm --url
it throws an error using packetsender to try and connect to the service:
packet sender log
Im not really sure what the reason for this could be, I think it has something to do with the fact that when I get the services it says on the external ip field. Also, when I try and retrieve the node IP using minikube ip
it gives an address, but when the minikube service --url
it gives the 127.0.0.1 address. In any case, using either one does not work.
2
Answers
it’s not working due to a port configuration mismatch.
You deployment container running on the
8006
but you have exposed the8080
and your target port is :--target-port=80
so due to this it’s not working.
Ideal flow of traffic goes like :
Below sharing the example for deployment and service
so things I have changed are
image
andtarget port
.Once your Node port service is up and running you will send the request on Port 80 or 31364
i will redirect the request internally to the target port which is 8006 for the container also.
Using this command you exposed your deployment on wrong target point
ideally it should be 8006
As I know the simplest way to expose the deployment to service we can run this command, you don’t expose the pod but expose the deployment.