Accessing kubernetics service from outside pod but within the cluster

10/16/2017

Am running several services on same port within my kubernetes cluster; so its like ser1, ser2, ser3 all using same port 8080. I can access these services from inside a pod as <serv-name>:8080 but can I also access them in same way from one of the host nodes i.e. outside a container but from one of the cluster nodes ?

I tried looking around but did not find any relevant discussion on this. Pls if someone may suggest.

my sample config

apiVersion: v1
kind: Service
metadata:
  name: svc1
  namespace: sample
  labels:
    app: svc1
spec:
  selector:
    app: app1
  ports:
  - name: psvc1
    port: 8080
    targetPort: 9090
    protocol: TCP
-- Mohit Gupta
kubernetes

1 Answer

10/16/2017

as Dries said, using cluster IP we can access the service from node.

kubectl run nginx --image=nginx --port=80 --expose=true

kubectl  get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP   9d
nginx        ClusterIP   10.103.206.246   <none>        80/TCP    52m


# curl 10.103.206.246:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
-- sfgroups
Source: StackOverflow