<p>Usually to access an external API you can just use its URL. But you can create a Service for it if you like, the type of service should be ExternalName as described in the documentation <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types</a></p>

CC BY-SA 4.0
2019-03-18T01:26:39.363Z
2019-03-18T01:26:39.363Z
Evgeny Zislis
<p>A service in kubernetes is (mostly) used for internal communication. If you want to access an external resource by domain/ip you can just do so. If you have an IP address and you would like to have some sort of domain connected to it, you could you am service with the external name field set to the up address (we use that for database purposes). An endpoint is automatically created for you when you create an service so you don’t nees to bother with that </p>

CC BY-SA 4.0
2019-03-17T22:45:46.760Z
2019-03-17T22:45:46.760Z
user1086801
<p>This is my first foray into Kubernetes land... I'm still pretty shaky on how things work and still wrapping my head around some of the concepts so please bear with me there. </p>

<p>The application I am deploying needs access to a couple of external third party http rest apis. What I <strong>believe</strong> I need from reading the docs is a service with an endpoint that points to the external rest apis ip. This is what I have in my helm templates:</p>

<p>service.yaml:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  labels:
    run: external_rest_service
  name: external_rest_service
spec:
  ports:
  - port: 443
</code></pre>

<p>My endpoint.yaml:</p>

<pre><code>kind: Endpoints
apiVersion: v1
metadata:
 name: external_rest_service
subsets:
 - addresses:
     - ip: https://www.someservice.com/api
   ports:
     - port: 443
</code></pre>

<p>This of course doesn't work because ip needs to be an ip address. However, when I do an nslookup of the rest api I get back 3 different ip addresses which I believe may be because of round robin dns. Oddly when I try any of the ip addresses directly via curl I don't get a response. My questions are.. </p>

<ul>
<li>Is this the correct or best practice approach to giving access to an outside resource from within my cluster?</li>
<li>Can I configure (and should I) configure Kubernetes to allow access via domain name instead of ip? If so.. where do I configure this? I'm not seeing it when searching the docs.</li>
</ul>

<p>If anyone could give me any guidance here I would really appreciate it. Thanks much!</p>

<kubernetes><helm><dns>
Accessing External REST api From Wthin Kubernetes Cluster
TheMethod
# Accessing External REST api From Wthin Kubernetes Cluster

(Asked by: username_0 on 2019-03-17)

This is my first foray into Kubernetes land... I'm still pretty shaky on how things work and still wrapping my head around some of the concepts so please bear with me there. 
The application I am deploying needs access to a couple of external third party http rest apis. What I believe I need from reading the docs is a service with an endpoint that points to the external rest apis ip. This is what I have in my helm templates:
service.yaml:
apiVersion: v1
kind: Service
metadata:
  labels:
    run: external_rest_service
  name: external_rest_service
spec:
  ports:
  - port: 443

My endpoint.yaml:
kind: Endpoints
apiVersion: v1
metadata:
 name: external_rest_service
subsets:
 - addresses:
     - ip: https://www.someservice.com/api
   ports:
     - port: 443

This of course doesn't work because ip needs to be an ip address. However, when I do an nslookup of the rest api I get back 3 different ip addresses which I believe may be because of round robin dns. Oddly when I try any of the ip addresses directly via curl I don't get a response. My questions are.. 

Is this the correct or best practice approach to giving access to an outside resource from within my cluster?
Can I configure (and should I) configure Kubernetes to allow access via domain name instead of ip? If so.. where do I configure this? I'm not seeing it when searching the docs.

If anyone could give me any guidance here I would really appreciate it. Thanks much!

**Tags:** kubernetes, helm, dns


---

## 2 answers

### Answer by username_1 on 2019-03-18. Score: 1 | Accepted answer

Usually to access an external API you can just use its URL. But you can create a Service for it if you like, the type of service should be ExternalName as described in the documentation <https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types>


---

### Answer by username_2 on 2019-03-17. Score: 1

A service in kubernetes is (mostly) used for internal communication. If you want to access an external resource by domain/ip you can just do so. If you have an IP address and you would like to have some sort of domain connected to it, you could you am service with the external name field set to the up address (we use that for database purposes). An endpoint is automatically created for you when you create an service so you don’t nees to bother with that


---

