<p>I am trying to schedule a cron job in a Kubernetes environment and I want to access the service internally instead of through the load balancer outside the cluster. Here's an example of my Service definition in YAML:</p>
<pre class="lang-yaml prettyprint-override"><code>---
apiVersion: v1
kind: Service
metadata:
  name: stage-api-svc
  labels:
    run: stage-api
  annotations:
    service.beta.kubernetes.io/do-loadbalancer-protocol: &quot;http&quot;
    service.beta.kubernetes.io/do-loadbalancer-redirect-http-to-https: &quot;true&quot;
    service.beta.kubernetes.io/do-loadbalancer-tls-ports: &quot;443&quot;
    service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-cookie-name: &quot;stage-cloud&quot;
    service.beta.kubernetes.io/do-loadbalancer-sticky-sessions-cookie-ttl: &quot;380&quot;
    service.beta.kubernetes.io/do-loadbalancer-healthcheck-path: &quot;/status&quot;
spec:
  selector:
    special: stage-api-svc
  type: LoadBalancer
  ports:
    - name: http
      port: 443
      targetPort: 8443
</code></pre>
<p>I've read in other comments to similar questions that I can use the <code>special</code> selector to reference the service. In my case, I would call:</p>
<pre class="lang-bash prettyprint-override"><code>curl -H &quot;InternalUser: true&quot; -X GET &quot;http://stage-api-svc:8443/cron&quot;
</code></pre>
<p>However, this doesn't seem to be working, so I'm wondering if I'm using the correct value for the selector in the service definition to reference it.</p>

pilotguy
<p>If you're trying to access the service within the k8s cluster, you should use use service port <code>443</code> instead of <code>8443</code>. Also make sure that:</p>
<ul>
<li>Service's <code>targetPort</code> is correctly mapping to Pod's container port</li>
<li>Both Service and Pod(s) are in same namespace. If they are in different NS, mention it in url as well like <code>http://stage-api-svc.namespace-name:443/cron</code></li>
<li><code>selectorLabels</code> used in <code>Service</code> are pointing correctly to Pod's labels.</li>
</ul>
