skip to Main Content

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

  • ✅The pod is running correctly as when I run kubectl get pods I get
NAME    READY   STATUS    RESTARTS   AGE
basic   1/1     Running   0          7m22s
  • That the service selecter matches the pod label
    • kubectl describe svc web-service-local | grep Selector | awk '{print $2}'
    • kubectl describe pod basic | grep Labels | awk '{print $2}'
  • ✅I can connect to the pod and nginx is running
    • kubectl exec --stdin --tty basic -- /bin/bash
    • curl localhost to retrieve the standard nginx homepage.
  • ✅ I can connect to the pod and nginx is running and can connect via the IP address
    • 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
  • ✅I can verify that both the service and the pod are in the default namespace
    • kubectl get pod basic --namespace default displays the pod
    • kubectl get svc web-service-local --namespace default
  • ✅I can verify that the DNS has been setup
    • 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}' Endpoint IP
  • kubectl exec --stdin --tty basic -- /bin/bash
  • curl **Endpoint IP**

2

Answers


  1. Chosen as BEST ANSWER

    The configuration worked. The problem was my local Minikube setup. Once I moved to AKS it was fine


  2. 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 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search