<p>Is it possible to send a http Rest request to another K8 Pod that belongs to the same Service in Kubernetes? </p>

<p>E. G.
Service name = UserService , 2 Pods (replica = 2)</p>

<pre><code>Pod 1 --&gt; Pod 2 //using pod ip not load balanced hostname 
Pod 2 --&gt; Pod 1
</code></pre>

<p>The connection is over Rest <code>GET 1.2.3.4:7079/user/1</code></p>

<p>The value for host + port is taken from <code>kubectl get ep</code></p>

<p>Both of the pod IP's work successfully outside of the pods but when I do a <code>kubectl exec -it</code> into the pod and make the request via CURL, it returns a 404 not found for the endpoint. </p>

<p><strong>Q</strong> What I would like to know if it is possible to make a request to another K8 Pod that is in the same Service? </p>

<p><strong>Q</strong> Why am I able to get a successful <code>ping 1.2.3.4</code>, but not hit the Rest API? </p>

<p><strong>below is my config files</strong></p>

<pre><code> #values.yml
replicaCount: 1

 image:
  repository: "docker.hosted/app"
  tag: "0.1.0"
  pullPolicy: Always
  pullSecret: "a_secret"

service:
 name: http
 type: NodePort
 externalPort: 7079
 internalPort: 7079

ingress:
 enabled: false
</code></pre>

<h1>deployment.yml</h1>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "app.fullname" . }}
  labels:
    app: {{ template "app.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    metadata:
      labels:
        app: {{ template "app.name" . }}
        release: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:

            - name: MY_POD_IP
              valueFrom:
               fieldRef:
                fieldPath: status.podIP
            - name: MY_POD_PORT
              value: "{{ .Values.service.internalPort }}"
          ports:
            - containerPort: {{ .Values.service.internalPort }}
          livenessProbe:
            httpGet:
              path: /actuator/alive
              port: {{ .Values.service.internalPort }}
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 1
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /actuator/ready
              port: {{ .Values.service.internalPort }}
          initialDelaySeconds: 60
          periodSeconds: 10
          timeoutSeconds: 1
          successThreshold: 1
          failureThreshold: 3
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
      imagePullSecrets:
        - name: {{ .Values.image.pullSecret }
</code></pre>

<h1>service.yml</h1>

<pre><code>kind: Service
metadata:
  name: {{ template "app.fullname" . }}
  labels:
    app: {{ template "app.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.externalPort }}
      targetPort: {{ .Values.service.internalPort }}
      protocol: TCP
      name: {{ .Values.service.name }}
  selector:
    app: {{ template "app.name" . }}
    release: {{ .Release.Name }}
</code></pre>

<h1>executed from master</h1>

<p><a href="https://i.stack.imgur.com/bizoF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bizoF.png" alt="executed from k8 master"></a> </p>

<h1>executed from inside a pod of the same MicroService</h1>

<p><a href="https://i.stack.imgur.com/LaMRn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LaMRn.png" alt="executed from inside a pod of the same MicroService"></a></p>

M_K
<blockquote>
  <p>Is it possible to send a http Rest request to another K8 Pod that belongs to the same Service in Kubernetes?</p>
</blockquote>

<p>For sure, yes, that's actually exactly why every Pod in the cluster has a cluster-wide routable address. You can programmatically ask kubernetes for the list of the Pod's "peers" by requesting the <code>Endpoint</code> object that is named the same as the <code>Service</code>, then subtract out your own Pod's IP address. It seems like you kind of knew that from <code>kubectl get ep</code>, but then you asked the question, so I thought I would be explicit that your experience wasn't an accident.</p>

<blockquote>
  <p>Q Why am I able to get a successful ping 1.2.3.4, but not hit the Rest API?</p>
</blockquote>

<p>We can't help you troubleshoot your app without some app logs, but the fact that you got a 404 and not "connection refused" or 504 or such means your <strong>connectivity</strong> worked fine, it's just the <em>app</em> that is broken.</p>
