K8s services
Zhengliang Wang edited at Mon Jul 01 2024
k8s

Document

In Kubernetes, a Service is a method for exposing a network application that is running as one or more Pods in your cluster.

Problem to tackle: with many nodes and pods of applications, how would the applications contact each other?

Service Types

NodePort

  • mapping a node port to a pod port
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  type: NodePort
  ports:
    - targetPort: 80
      port: 80
      nodePort: 30008 # range between 30000 - 32767
  selector:
    app: nginx
    type: nginx

ClusterIp

  • group applications into one service interface. (gateway alike)
apiVersion: v1
kind: Service
metadata:
  name: back-end
spec:
  type: ClusterIP # default
  ports:
    - targetPort: 80
      port: 80
  selector:
    app: myapp
    type: back-end

LoadBalancer

apiVersion: v1
kind: Service
metadata:
  name: back-end
spec:
  type: LoadBalancer
  ports:
    - targetPort: 80
      port: 80
      nodePort: 30008 # range between 30000 - 32767