I am new to K8s, and I am facing issues trying to connect to K8s NodePort service from outside the cluster.
I am unable to load the nginx default page when I try accessing it from my local machine using the URL: http://localhost:31008
I understand this is a common problem and I referred the below solutions,
CodePudding user response:
The nginx default port is 80
not 8080
. Siince you did not change the nginx config, you need to change the port
and targetPort
fields in your service to 80
.
CodePudding user response:
There is an issue in the target port config as Nginx run on default port 80
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: front-end
name: nginx
ports:
- port: 8080
targetPort: 80
nodePort: 31008
The target port should be 80
Config of Nginx :
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
selector:
matchLabels:
run: my-nginx
replicas: 2
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 80
Ref document : https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/