<p>I have 2 pods created. one is grafana and another is influx pod. I need to configure influx in grafana. I did see the below example. I got bit confused by the way its configured. Below is deployment and service file.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: influxdb
  labels:
    app: influxdb
spec:
  template:
    metadata:
      labels:
        app: influxdb
    spec:
      containers:
      - name: influxdb
        image: influxdb
        ports:
        - containerPort: 8083
          name: admin
        - containerPort: 8086
          name: http
        resources:
          limits:
            memory: 2048Mi
            cpu: 100m  
        volumeMounts:
        - name: influxdb-data
          mountPath: /var/lib/influxdb
      volumes:
      - name: influxdb-data
        persistentVolumeClaim:
          claimName: influxdb-pvc-vol
</code></pre>

<p>Service file</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: influxdb
  labels:
    app: influxdb
spec:
  ports:
    - port: 3306
  selector:
    app: influxdb
  clusterIP: None
</code></pre>

<p>What does <code>clusterIP: None</code> do? he has exposed 3306 port and mapped it to node port 3306. So i believe i can access from other pod using 3306 port and its IP. But here i see i am able to access via <code>http://influxdb:8086</code> How am i able to access via <a href="http://influxdb:8086" rel="nofollow noreferrer">http://influxdb:8086</a>?</p>

Hacker
<p>I can explain what's happening and why this works, but I still think this configuration doesn't make sense.</p>

<p>The Deployment creates a Pod that runs InfluxDB which listens by default on port 8086. The <code>containerPort</code> here is purely informational, see the following from the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/" rel="nofollow noreferrer">Pod spec reference</a>:</p>

<blockquote>
  <p>primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default "0.0.0.0" address inside a container will be accessible from the network.</p>
</blockquote>

<p>Now to the Service, which is created with a port 3306, which is odd but in this case doesn't matter because this is a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">Headless Service</a>. A headless service is a means to tell Kubernetes you don't want it's fancy networking features (like kube-proxy load balancing), instead you just want it to create DNS records for you. By specifying <code>ClusterIP: None</code> you essentially make this a headless service. Given that this service is not actually serving any traffic, the "Port" field here is meaningless.</p>

<p>Now let's review what happens when you access <a href="http://influxdb:8086" rel="nofollow noreferrer">http://influxdb:8086</a>:</p>

<ol>
<li>your http client resolves the host <code>influxdb</code> to the Pod IP. This is possible thanks to the headless service. Note again that the host resolves to the Pod IP, not a Service IP.</li>
<li>Since the Pod is serving on 8086, and since you reached it directly in it's private IP, it accepts your request and you have your reply.</li>
</ol>
