Cannot access exposed IP in kubernetes

12/2/2017

I have a service deployed and running in kubernetes

ssk181993@sdn-assign2:~$ kubectl get svc
NAME                             TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
kubernetes                       ClusterIP      10.11.240.1     <none>           443/TCP          19d
weather-view-deployment          LoadBalancer   10.11.250.200   130.211.181.24   9082:32173/TCP   1d
weather-view-service             NodePort       10.11.243.238   <none>           9082:32640/TCP   1d

When I try to access the external ip like,

ssk181993@sdn-assign2:~$ curl 130.21.181.24:9082
curl: (7) Failed to connect to 130.21.181.24 port 9082: Connection timed out

Any suggestions?

Update--

service.yml

`apiVersion: v1
kind: Service
metadata:
  name: weather-view-service
spec:
  type: LoadBalancer
  loadBalancerIP: 78.11.24.25
  ports:
    -
      port: 9082
      targetPort: 9082
  selector:
    app: weather-view
  type: NodePort
status:
  loadBalancer: {}`

deployment.yml

`apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: weather-view-deployment
spec:
  replicas: 2 # tells deployment to run 2 pods matching the template
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template: # create pods using pod definition in this template
    metadata:
      labels:
        app: weather-view
    spec:
      containers:
      - name: weather-view
        image: ##dockerhubimage##
        ports:
        - containerPort: 9082`

Refer the image for folder structure in git. https://i.stack.imgur.com/d0BAZ.jpg

-- Sathish
google-cloud-platform
kubernetes

1 Answer

12/2/2017

You are trying to access the internal target port, If you set your service type field to NodePort, the Kubernetes master will allocate a port from a flag-configured range (default: 30000-32767).

So try to do curl http://130.211.181.24:32173

See this link for more information.

-- Gal Shaboodi
Source: StackOverflow