<p>I have PHP app+Apache on a Kubernetes POD. The PHP app, access Elasticsearch API on port 9200, and show a simple website, to the users, on port 5000.</p>

<p>I run proxy, using <code>kubectl proxy --address='0.0.0.0' --port=8001 --accept-hosts='.*'</code>.</p>

<p>When I enter to <code>"http://localhost:8001/api/v1/namespaces/default/pods/website/proxy/"</code>, I see the following error:</p>

<pre><code>Error: 'dial tcp 172.17.0.6:5000: connect: connection refused'
Trying to reach: 'http://172.17.0.6:5000/'
</code></pre>

<p>*172.17.0.6 is the POD ip address.</p>

<p>This is the website POD yaml:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: website
  labels:
    app: website
spec:
  containers:
  - name: website
    image: website_k8s:latest
    ports:
    - containerPort: 5000
    - containerPort: 80
</code></pre>

<p>This is the dockerfile of website_k8s:latest:</p>

<pre><code>FROM php:7.0-apache
RUN echo "ServerName 0.0.0.0" &gt;&gt; /etc/apache2/apache2.conf
COPY ./index.php /var/www/html/
EXPOSE 5000
</code></pre>

<hr>

<p>I also tried to run service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: website-service
spec:
  ports:
  - port: 5000
    targetPort: 80
    protocol: TCP
    name: serving
  - port: 80
    targetPort: 9200
    protocol: TCP
    name: readfromelasticsearch
  selector:
    app: website
</code></pre>

<p>And when I enter to <code>http://localhost:8001/api/v1/namespaces/default/services/website-service/proxy/</code>, I see:</p>

<pre><code>{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {

  },
  "status": "Failure",
  "message": "no endpoints available for service \"website-service\"",
  "reason": "ServiceUnavailable",
  "code": 503
}
</code></pre>

<p>Even though, when I run <code>$kubectl get endpoints website-service</code>, I see:</p>

<pre><code>NAME              ENDPOINTS                       AGE
website-service   172.17.0.6:80,172.17.0.6:9200   59m
</code></pre>

<p>I see the service's POD endpoint.</p>

<p>How could I access my website via proxy?</p>

Yagel
<p>The problem is that Apache is listening on port 80, not 5000.</p>

<p>If you remove <code>containerPort: 5000</code> then you can access the website via <code>http://localhost:8001/api/v1/namespaces/default/pods/website/proxy/</code>.</p>

<p>Secondly, the endpoints you see for the service are internal to the cluster.
So, you can access the service through those IP endpoints from within a pod: <code>kubectl exec website -- curl 172.17.0.6/</code>.
If you want to expose your service externally, the service should be of type <code>NodePort</code> or <code>LoadBalancer</code>.</p>

<p>Finally, the problem you have when querying the service through the proxy is that, when you give a name to a port, you have to include it in the proxy call: <code>curl localhost:8001/api/v1/namespaces/default/services/website-service:serving/proxy/</code>.</p>
