Services: ClusterIP, NodePort, LoadBalancer, Ingress


Kubernetes - Services Explained

kubernetes Services


ClusterIP

kubernetes ClusterIP


apiVersion: v1
kind: Service
metadata:
  name: my-internal-service
spec:
  selector:
    app: my-app
  type: ClusterIP
  ports:
  - name: http
    port: 80
    targetPort: 80
    protocol: TCP


NodePort

kubernetes NodePort


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


LoadBalancer

kubernetes LoadBalancer


kind: Service
apiVersion: v1
metadata:
    name: loadbalancer-service
spec:
    selector:
        app: app-lb
    ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
    clusterIP: <internalIP>
    loadBalancerIP: <externalIP>
    type: LoadBalancer


Ingress

kubernetes Ingress


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
  backend:
    serviceName: other
    servicePort: 8080
  rules:
  - host: foo.mydomain.com
    http:
      paths:
      - backend:
          serviceName: foo
          servicePort: 8080
  - host: mydomain.com
    http:
      paths:
      - path: /bar/*
        backend:
          serviceName: bar
          servicePort: 8080


Скапитализжено:

https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0