"CrashLoopBackOff" error disappeared, but new error "Connection Refuesd"

2/26/2020

Using command: [ "/bin/bash", "-c", "--" ] args: [ "while true; do sleep 30; done;" ], I sovled "CrashLoopBackoff" errors

apiVersion: v1
kind: Pod
metadata:
  name: pod-apigw2
spec:
  selector:
      app: apigw2
  containers:
      - name: apigw2
        image: parkdongwoo/apigw_test:v1
        imagePullPolicy: Always
        ports:
                - name: port-apigw2
                  containerPort: 8080
  command: [ "/bin/bash", "-c", "--" ]
  args: [ "while true; do sleep 30; done;" ]

However, refused error occurred while linking service.

Below is my service yaml. I configured NodePort to receive service requests from outside

apiVersion: v1
kind: Service
metadata:
  name: apigw-nodeport
spec:
  type: NodePort
  ports:
      - name: port-apigw
        port: 80      
        targetPort: 8001
  selector:
    app: apigw2 

The status of the pod and the state of svc are as follows:

al8-1@al8-1:~/kuber_test/pod_nginx$ kubectl get pods -o wide
NAME         READY   STATUS    RESTARTS   AGE     IP             NODE    NOMINATED NODE   READINESS GATES
nginx        1/1     Running   0          6d3h    192.168.4.2    al8-2   <none>           <none>
pod-apigw2   1/1     Running   0          5m17s   192.168.4.56   al8-2   <none>           <none>

al8-1@al8-1:~/kuber_test/pod_nginx$ kubectl get svc -o wide
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE     SELECTOR
apigw-nodeport   NodePort    10.108.177.5     <none>        80:31050/TCP     68m     app=apigw2

When I tried to curl the nodePort to see if it was normally open, the following error occurred:

al8-1@al8-1:~/kuber_test/pod_nginx$ curl 192.168.xx.xx:31050
curl: (7) Failed to connect to 192.168.xx.xx port 31050: connection refuesd

I don't know how to solve it now.

Please let me know if there is another way to solve "CrashLoopBackOff" or how can I resolve "Connection refused"?

-- dongwoo_park
kubernetes

1 Answer

2/26/2020

The targetPort in service needs to match with containerPort in pod. You have 8081 as targetPort but 8080 as containerPort.

If it does not work even after matching targetport with container port then that means the container is not listening at all on that port.

-- Arghya Sadhu
Source: StackOverflow