Connection timedout when attempting to access any service in kubernetes

11/17/2017

I've create a deployment and a service and deployed them using kubernetes, and when i tried to access them by curl, always i got a connection timed out error.

Here's my yml files:

Deployment.yml

        apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      labels:
        app: locations-service
      name: locations-service
      namespace: default
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: locations-service
      template:
        metadata:
          labels:
            app: locations-service
        spec:
          containers:
            - image: dropwizard:latest
              imagePullPolicy: Never # just for testing!
              name: locations-service
              ports:
                - containerPort: 8080
                  protocol: TCP
                  name: app-port
                - containerPort: 8081
                  protocol: TCP
                  name: admin-port
              resources: {}
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler

Service.yml

        apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: locations-service
      name: locations-service
      namespace: default
    spec:
      type: NodePort
      externalTrafficPolicy: Cluster
      ports:
      - name: "8080"
        port: 8080
        targetPort: 8080
        protocol: TCP
      - name: "8081"
        port: 8081
        targetPort: 8081
        protocol: TCP
      selector:
        app: locations-service

Also i tried to add ingress routes, and tried to hit them but still the same problem occur.

Note that the application is successfully deployed, and i can check the logs from k8s dashboard enter image description here

Another example, i have the following svc

kubectl describe service webapp1-svc
Name:                     webapp1-svc
Namespace:                default
Labels:                   app=webapp1
Annotations:              <none>
Selector:                 app=webapp1
Type:                     NodePort
IP:                       10.0.0.219
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
NodePort:                 <unset>  30080/TCP
Endpoints:                172.17.0.4:80
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

and tried to access it using

curl -v 10.0.0.219:30080
* Rebuilt URL to: 10.0.0.219:30080/
*   Trying 10.0.0.219...
* connect to 10.0.0.219 port 30080 failed: Connection timed out
* Failed to connect to 10.0.0.219 port 30080: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to 10.0.0.219 port 30080: Connection timed out
-- M1M6
deployment
kubernetes

0 Answers