<p>I'm using minikube version: v1.25.1, win10, k8s version 1.22</p>
<p>There is 1 node, 2 pods on it: <code>main</code> and <code>front</code>, 1 service - <code>svc-main</code>.</p>
<p>I'm trying to exec into front and call main thru service and see some msg confirming connection is ok.</p>
<p>main.yaml:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    app: main
  name: main
  namespace: default
spec:
  containers:
    - name: main
      image: nginx
      command: [&quot;/bin/sh&quot;,&quot;-c&quot;]
      args: [&quot;while true; do echo date; sleep 2; done&quot;]
</code></pre>
<p>front.yaml:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    app: front
  name: front
spec:
  containers:
  - image: nginx
    name: front
    command:
    - /bin/sh
    - -c
    - while true; echo date; sleep 2; done
</code></pre>
<p>service is created like this:</p>
<pre><code>k expose pod ngin --name=svc-main --type=ClusterIP --port=80 --target-port=80

k get svc
NAME         TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
svc-main     ClusterIP 10.104.26.249   &lt;none&gt;        80:31775/TCP   11m
</code></pre>
<p>When I try to curl from inside front it says &quot;Could not resolve host: svc-main&quot;</p>
<pre><code> k exec front -it -- sh
 curl svc-main:80
</code></pre>
<p>or this</p>
<pre><code>curl http://svc-main:80

curl 10.104.26.249:80
</code></pre>
<p>I tried the port 31775, same result. What am I doing wrong?!</p>

<p>The problem is when you are creating a Kubernetes pod using your yaml file, you are overwriting the default Entrypoint and Cmd defined in nginx docker image with your custom command and args:</p>
<pre class="lang-yaml prettyprint-override"><code>command: [&quot;/bin/sh&quot;,&quot;-c&quot;]
args: [&quot;while true; do echo date; sleep 2; done&quot;]
</code></pre>
<p>That's why nginx web server doesn´t work in created pods.
You should remove these lines, delete running pods, and create new pods. After that, you will be able to reach the nginx web page by running</p>
<pre class="lang-sh prettyprint-override"><code># curl svc-main
</code></pre>
<p>within your front pod.</p>
<p>You can read more info about defining a command and arguments for a container in a Pod <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/" rel="nofollow noreferrer">here</a></p>
<p>And there is a good article about Docker CMD and Entrypoint <a href="https://www.cloudbees.com/blog/understanding-dockers-cmd-and-entrypoint-instructions" rel="nofollow noreferrer">here</a></p>
