So I've read a bunch of these similar questions/issues on stackoverflow and I understand it enough but not sure what I am missing.
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: dev-namespace
labels:
web: nginx
spec:
replicas: 2
selector:
matchLabels:
web: nginx
template:
metadata:
labels:
web: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 8080
service.yml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
web: nginx
ports:
- protocol: TCP
port: 80
targetPort: 8080
This is my minikube ip:
$ minikube ip
192.168.49.2
This is the service
$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-service NodePort 10.104.139.228 <none> 80:30360/TCP 14
This is the deployment
$ kubectl get deployments.apps
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 14h
This is the pods
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-deployment-5b78696cc8-9fpmr 1/1 Running 0 14h 172.17.0.6 minikube <none> <none>
nginx-deployment-5b78696cc8-h4m72 1/1 Running 0 14h 172.17.0.4 minikube <none> <none>
This is the endpoints
$ kubectl get endpoints
NAME ENDPOINTS AGE
nginx-service 172.17.0.4:8080,172.17.0.6:8080 14h
But when I try to curl 10.104.139.228:30360 it just hangs. When I try to curl 192.168.49.2:30360 I get the Connection refused
I am sure that using NodePort means I need to use the node ip and that would be the server's local IP since I am using minikube and control plane and worker are in the same server.
What am I missing here? Please help, this is driving me crazy. I should mention that I am able to kubectl exec -ti pod-name -- /bin/bash and if I do a curl localhost I do get the famous response "Welcome to NGINX"
Nevermind :/ I feel very foolish I see that the mistake was the container ports :/ my nginx pods are listening on port 80 not port 8080
For anyone out there, I updated my config files to this:
service.yml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: busy-qa
spec:
type: NodePort
selector:
web: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: busy-qa
labels:
web: nginx
spec:
replicas: 2
selector:
matchLabels:
web: nginx
template:
metadata:
labels:
web: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Now when I curl I get the NGINX response
$ curl 192.168.49.2:31168
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>