<p>I'm trying to execute an application inside a kubernetes cluster.
I used to launch the application with docker-compose without problems, but when I create
my kubernetes deployment files, I am not able to access the service inside the cluster even after exposing them. here is my deployment file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
      matchLabels:
        app: myapp
  # type: LoadBalancer
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: jksun12/vdsaipro
       # command: [&quot;/run.sh&quot;]
        ports:
        - containerPort: 80
        - containerPort: 3306
   # volumeMounts:
   #     - name: myapp-pv-claim
   #       mountPath: /var/lib/mysql
   #   volumes:
   #   - name: myapp-pv-claim
   #     persistentVolumeClaim:
   #       claimName: myapp-pv-claim
---
apiVersion: apps/v1
kind: PersistentVolumeClaim
metadata:
  name: myapp-pv-claim
  labels:
    app: myapp
spec:
  accesModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 4Gi
</code></pre>
<p>Here is the result of</p>
<blockquote>
<p>kubectl describe service myapp-service</p>
</blockquote>
<p>:</p>
<pre><code>Name:                     myapp-service
Namespace:                default
Labels:                   &lt;none&gt;
Annotations:              &lt;none&gt;
Selector:                 app=myapp
Type:                     NodePort
IP:                       10.109.12.113
Port:                     port-1  80/TCP
TargetPort:               80/TCP
NodePort:                 port-1  31892/TCP
Endpoints:                172.18.0.5:80,172.18.0.8:80,172.18.0.9:80
Port:                     port-2  3306/TCP
TargetPort:               3306/TCP
NodePort:                 port-2  32393/TCP
Endpoints:                172.18.0.5:3306,172.18.0.8:3306,172.18.0.9:3306
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>
<p>And here are the errors that I get when I try to access them:</p>
<blockquote>
<p>curl 172.17.0.2:32393</p>
</blockquote>
<pre><code>curl: (1) Received HTTP/0.9 when not allowed
</code></pre>
<p>And here is the next result when I try to access the other port</p>
<blockquote>
<p>curl 172.17.0.2:31892</p>
</blockquote>
<p>curl: (7) Failed to connect to 172.17.0.2 port 31892: Connection refused
curl: (7) Failed to connect to 172.17.0.2 port 31892: Connection refused</p>
<p>I'm running ubuntu server 20.04.1 LTS. The manip is on top of minikube.
Thanks for your help.</p>

Joseph Tankoua
<p>If you are accessing the service from inside the cluster use ClusterIP as the IP. So curl should be <code>10.109.12.113:80</code> and <code>10.109.12.113:3306</code></p>
<p>In case accessing it from outside the cluster then use <code>NODEIP</code> and <code>NODEPORT</code>. So curl should be on <code>&lt;NODEIP&gt;:32393</code> and <code>&lt;NODEIP&gt;:31892</code></p>
<p>From inside the cluster I would also use POD IPs directly to understand if the issue is at service level or pod level.</p>
<p>You need to make sure that the application is listening on port <code>80</code> and port <code>3306</code>. Only mentioning <code>containerPort</code> as <code>80</code> and <code>3306</code> does not make the application listen on those ports.</p>
<p>Also make sure that the application code inside the pod is listening on <code>0.0.0.0</code> instead of <code>127.0.0.1</code></p>
