简体   繁体   中英

Accessing kubernetics service from outside pod but within the cluster

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 ie 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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM