k8s--網絡模式

一、clusteripnode

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
[root@k8s-master rc-test]# kubectl get svc
NAME         CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
kubernetes   10.254.0.1      <none>        443/TCP    9d
my-service   10.254.233.44   <none>        80/TCP     16s
mysql        None            <none>        3306/TCP   8d

[root@k8s-master rc-test]# kubectl get ep
NAME ENDPOINTS AGE
kubernetes 192.168.137.110:6443 9d
my-service 172.168.69.2:80,172.168.95.2:80 9m
mysql 172.168.69.3:3306 8dmysql

此種方式能夠在k8s內部使用,好比創建一個busybox,在busybox上面,能夠訪問10.254.233.44nginx

在node上面,也能夠使用endpoint的ip訪問,好比在master上面訪問172.168.69.2sql

 

 

二、NodePortapi

kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30062app

[root@k8s-master rc-test]# kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.254.0.1 <none> 443/TCP 10d
my-service 10.254.209.157 <nodes> 80:30062/TCP 5m
mysql None <none> 3306/TCP 8dspa

 

[root@k8s-master rc-test]# kubectl get ep
NAME ENDPOINTS AGE
kubernetes 192.168.137.110:6443 10d
my-service 172.168.69.2:80,172.168.95.2:80 6m
mysql 172.168.69.3:3306 8dcode


相比clusterIP,多了一個node上面的接口,cluster的兩種方式仍是能夠訪問。blog

另外node IP方式也能夠訪問了。接口

相關文章
相關標籤/搜索