<p>I have a corporate network(10.22.<em>.</em>) which hosts a Kubernetes cluster(10.225.0.1). How can I access some VM in the same network but outside the cluster from within the pod in the cluster?</p>

<p>For example, I have a VM with IP 10.22.0.1:30000, which I need to access from a Pod in Kubernetes cluster. I tried to create a Service like this</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: vm-ip
spec:
  selector:
    app: vm-ip
  ports:
    - name: vm
      protocol: TCP
      port: 30000
      targetPort: 30000
  externalIPs:
    - 10.22.0.1
</code></pre>

<p>But when I do "curl <a href="http://vm-ip:30000" rel="nofollow noreferrer">http://vm-ip:30000</a>" from a Pod(kubectl exec -it), it returns "connection refused" error. But it works with "google.com". What are the ways of accessing the external IPs?</p>

passwd
<p>You can create an <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.12/#endpoints-v1-core" rel="noreferrer">endpoint</a> for that. </p>

<p>Let's go through an example: </p>

<p>In this example, I have a http server on my network with IP <code>10.128.15.209</code> and I want it to be accessible from my pods inside my Kubernetes Cluster. </p>

<p>First thing is to create an endpoint. This is going to let me create a service pointing to this endpoint that will redirect the traffic to my external http server. </p>

<p>My endpoint manifest is looking like this:</p>

<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: http-server
subsets:
  - addresses:
      - ip: 10.128.15.209
    ports:
      - port: 80
</code></pre>

<pre><code>$ kubectl apply -f http-server-endpoint.yaml
endpoints/http-server configured
</code></pre>

<p>Let's create our service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: http-server
spec:
  ports:
    - port: 80
      targetPort: 80
</code></pre>

<pre><code>$ kubectl apply -f http-server-service.yaml
service/http-server created
</code></pre>

<p>Checking if our service exists and save it's clusterIP for letter usage:</p>

<pre><code>user@minikube-server:~$$ kubectl get service
NAME          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
http-server   ClusterIP   10.96.228.220   &lt;none&gt;        80/TCP    30m
kubernetes    ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP   10d
</code></pre>

<p>Now it's time to verify if we can access our service from a pod:</p>

<pre><code>$ kubectl run ubuntu -it --rm=true --restart=Never --image=ubuntu bash
</code></pre>

<p>This command will create and open a bash session inside a ubuntu pod.</p>

<p>In my case I'll install curl to be able to check if I can access my http server. You may need install mysql:</p>

<pre><code>root@ubuntu:/# apt update; apt install -y curl
</code></pre>

<p>Checking connectivity with my service using clusterIP:</p>

<pre><code>root@ubuntu:/# curl 10.128.15.209:80
Hello World!
</code></pre>

<p>And finally using the service name (DNS):</p>

<pre><code>root@ubuntu:/# curl http-server
Hello World!
</code></pre>

<p>So, in your specific case you have to create this: </p>

<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: vm-server
subsets:
  - addresses:
      - ip: 10.22.0.1
    ports:
      - port: 30000
---
apiVersion: v1
kind: Service
metadata:
  name: vm-server
spec:
  ports:
    - port: 30000
      targetPort: 30000
</code></pre>
