Kubernetes组件Service

简介:

通过相应的策略将Pod中提供的服务暴露给外界访问,通过Labels和selector将对应的Pod进行绑定过,也就是所谓的服务发现。

Service三种类型:

ClusterIP:自动生成一个虚拟的VIP可通过访问改VIP+Port实现访问服务,同时也做到了负载均衡效果;

apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: nginx
spec:
  type: ClusterIP
  selector:
    app: nginx
  ports:
    - name: nginx
      targetPort: 80
      port: 80

Headless Service:相当于没有VIP的ClusterIP,属于ClasterIP但没有VIP实现不了负载均衡,只需要指定type类型为None;

apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: nginx
spec:
  type: "None"
  selector:
    app: nginx
  ports:
    - name: nginx
      targetPort: 80
      port: 80

NodePort:每个Node通过ipvs策略以及kube-proxy将Pod的虚拟IP+Port转发到每一个Node的端口,Client可以通过每一个node:port来访问Pod提供的服务,master不参与,默认Node暴露Port>30000

apiVerion: v1
kind: Service
metadata:
  name: nginx
  namespace: nginx
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - name: nginx
      nodePort: 30001
      targetPort: 80
      port: 80
发布了62 篇原创文章 · 获赞 16 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_41674452/article/details/103840107