I have the following pod definition to run a basic instance of nginx
---
apiVersion: v1
kind: Pod
metadata:
name: basic
labels:
appName: static-website
spec:
containers:
- image: nginx
name: basic
I have made the following service definition
apiVersion: v1
kind: Service
metadata:
name: web-service-local
spec:
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30080
selector:
appName: static-website
❌ When I try to access the nginx page via the service IP it get's stuck
kubectl exec --stdin --tty basic -- /bin/bash
curl web-service-local
I have verified successfully that
kubectl get pods
I get NAME READY STATUS RESTARTS AGE
basic 1/1 Running 0 7m22s
kubectl describe svc web-service-local | grep Selector | awk '{print $2}'
kubectl describe pod basic | grep Labels | awk '{print $2}'
kubectl exec --stdin --tty basic -- /bin/bash
curl localhost
to retrieve the standard nginx homepage. kubectl get pods -l appName=static-website -o go-template='{{range.items}}{{.status.podIP}}{{"\n"}}{{end}}'
, returns the POD IP kubectl exec --stdin --tty basic -- /bin/bash
apt update && apt upgrade && apt install dnsutils -y
curl **POD IP**
( POD IP ) is from first command kubectl get pod basic --namespace default
displays the pod kubectl get svc web-service-local --namespace default
kubectl exec --stdin --tty basic -- /bin/bash
apt update && apt upgrade && apt install dnsutils -y
nslookup web-service-local
, nslookup web-service-local.default
and nslookup web-service-local.default.svc.cluster.local
all return the same Server: 10.96.0.10
Address: 10.96.0.10#53
Name: web-service-local.default.svc.cluster.local
Address: 10.106.61.252
✅ I have verified that I can access nginx via the Endpoint IP
kubectl describe svc web-service-local | grep Endpoints | awk '{print $2}'
kubectl describe svc web-service-local | grep Endpoints | awk '{print $2}'
Endpoint IP kubectl exec --stdin --tty basic -- /bin/bash
curl **Endpoint IP**
Since you have NodePort service type implementation, please try with nodeIP:NodePort from the browser or perform the curl as a NodePort service is the most primitive way to get external traffic directly to your service. NodePort, as the name implies, opens a specific port on all the Nodes (the VMs), and any traffic that is sent to this port is forwarded to the service.
curl -kvv Nodeip:NodePort
The configuration worked. The problem was my local Minikube setup. Once I moved to AKS it was fine
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.