kubernetes Service 暴露服务的几种方式

kubernetes service暴露服务到目前为止,一共有以下几种方法

ClusterIP 方式

kubernetes 默认就是这种方式,是集群内部访问的方式

spec:
  clusterIP: 10.0.0.1
  ports:
  - name: http

NodePort 方式

NodePort方式主要通过节点IP加端口的形式暴露端口
访问方式:protocol://:.

heapster                10.3.129.117          80:30003/TCP    14d

apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"creationTimestamp":"2017-05-24T06:38:16Z","labels":{"kubernetes.io/name":"heapster","plugin":"heapster"},"name":"heapster","namespace":"kube-system","resourceVersion":"173906247","selfLink":"/api/v1/namespaces/kube-system/services/heapster","uid":"91470fbb-404b-11e7-ba41-5254eec04736"},"spec":{"clusterIP":"10.3.129.117","externalTrafficPolicy":"Cluster","ports":[{"nodePort":30003,"port":80,"protocol":"TCP","targetPort":8082}],"selector":{"k8s-app":"heapster"},"sessionAffinity":"None","type":"NodePort"},"status":{"loadBalancer":{}}}
  creationTimestamp: 2018-07-25T03:22:01Z
  labels:
    kubernetes.io/name: heapster
    plugin: heapster
  name: heapster
  namespace: kube-system
  resourceVersion: "789489505"
  selfLink: /api/v1/namespaces/kube-system/services/heapster
  uid: e56886a2-8fb9-11e8-acd2-5254171bf8db
spec:
  clusterIP: 10.3.129.117
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30003
    port: 80
    protocol: TCP
    targetPort: 8082
  selector:
    k8s-app: heapster
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

LoadBalancer 方式

这种方式主要是利用其他第三方的LB暴露服务的,谷歌或者亚马逊的LB等等

kind: Service
apiVersion: v1
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
  - protocol: TCP
    port: 80
    targetPort: 9376
  clusterIP: 10.0.171.239
  loadBalancerIP: 78.11.24.19
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 146.148.47.155

ExternalName 方式

这种方式主要是通过CNAME实现的,在kubernetes 1.7.x以及以上才支持这种方式,例如

kind: Service
apiVersion: v1
metadata:
  name: my-service
  namespace: prod
spec:
  type: ExternalName
  externalName: my.database.example.com

访问时,kube-dns服务直接解析到指定的Cnamemy.database.example.com这个域名上

参考:Publishing services - service types

你可能感兴趣的:(kubetnetes)