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

<pre><code>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;" ]
</code></pre>

<p>However, refused error occurred while linking service.</p>

<p>Below is my service yaml. I configured NodePort to receive service requests from outside</p>

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

<p>The status of the pod and the state of svc are as follows:</p>

<pre><code>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   &lt;none&gt;           &lt;none&gt;
pod-apigw2   1/1     Running   0          5m17s   192.168.4.56   al8-2   &lt;none&gt;           &lt;none&gt;

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     &lt;none&gt;        80:31050/TCP     68m     app=apigw2
</code></pre>

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

<pre><code>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
</code></pre>

<p>I don't know how to solve it now. </p>

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

dongwoo_park
<p>The targetPort in service needs to match with containerPort in pod. You have 8081 as targetPort but 8080 as containerPort.</p>

<p>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.</p>
