Kubernetes Connection Timeout

6/18/2019

I have deployed a small app using the following yaml.

apiVersion: apps/v1
kind: Deployment
metadata:
    name: simpledotnetapi-deployment
spec:
    replicas: 1
    selector:
        matchLabels:
            app: simpledotnetapi-pod
    template:
        metadata:
            labels:
                app: simpledotnetapi-pod
        spec:
            imagePullSecrets:
              - name: kimagereadersecret
            containers:
              - name: simpledotnetapi
                image: docker.io/coreyperkins/simpledotnetapi:latest
                ports:
                  - containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
    name: simpledotnetapi-service
spec:
    type: LoadBalancer
    ports:
    - port: 80
      targetPort: 5000
      nodePort: 30008
    selector:
       app: simpledotnetapi-pod
       type: front-end

The services tab in the K8 dashboard shows the following:

Name: simpledotnetapi-service
Cluster IP: 10.0.133.156
Internal Endpoints:
simpledotnetapi-service:80 TCP
simpledotnetapi-service:30008 TCP
External Endpoints:
13.77.76.204:80

-- output from kubectl.exe describe svc simpledotnetapi-service

λ kubectl.exe describe svc simpledotnetapi-service
Name:                     simpledotnetapi-service
Namespace:                default
Labels:                   <none>
Annotations:              kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"simpledotnetapi-service","namespace":"default"},"spec":{"ports":[{"nodePort":3...
Selector:                 app=simpledotnetapi-pod,type=front-end
Type:                     LoadBalancer
IP:                       10.0.133.156
LoadBalancer Ingress:     13.77.76.204
Port:                     <unset>  80/TCP
TargetPort:               5000/TCP
NodePort:                 <unset>  30008/TCP
Endpoints:                <none>
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason                Age               From                Message
  ----    ------                ----              ----                -------
  Normal  EnsuringLoadBalancer  33m (x4 over 2h)  service-controller  Ensuring load balancer
  Normal  EnsuredLoadBalancer   33m (x4 over 2h)  service-controller  Ensured load balancer

When I go to the pod I can see that my docker container is running just fine, on port 5000, as instructed. However, when I navigate to http://13.77.76.204/api/values I should see an array returned, but instead the connection times out (ERR_CONNECTION_TIMED_OUT in Chrome). I have tested this Docker container locally and it works just fine. My assumption is that I've muckered up the "containerPort" on the pod spec (under Deployment), but I am certain that the container is alive on port 5000. Perhaps I am missing some configuration bits? However, looking through samples and the documentation I haven't been able to find out why the connection is not being made to the pod but I do not see any activity in the pods logs aside from the initial launch of the app.

-- coreyperkins
docker
kubernetes

1 Answer

6/18/2019

There are label/selector mismatches in your pod/service definitions.

You are using app: simpledotnetapi-pod for pod template, and app: simpledotnetapi as a selector in your service definition. Edit one of them to match.

Also the label type: front-end doesn't exist on your pod template. You need to add it, or maybe remove this from the service selectors.

After that, your endpoint list should have entries for your pod when it becomes ready.

-- Eduardo Baitello
Source: StackOverflow