6.2.1 Label与松耦合

  Service与Pod之间是通过Label和Label筛选器(selector)松耦合在一起的

※ 所谓松耦合(Loose Coupling)是指一种系统或组件之间的设计原则,它强调组件之间的低依赖性和高独立性

所有匹配的Pod必须拥有Service Label筛选器中定义的所有Label

所匹配的Pod也可以拥有其它不再Service Label筛选器中的Label。

示例

Service代码

apiVersion: v1
kind: Service
metadata:
  name: hello-svc
  labels:
    app: hello-world
spec:
  type: NodePort
  ports:
  - port: 8080
    nodePort: 30001
    protocol: TCP
  selector:
    app: hello-world

Deployment代码

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-deploy
spec:
  replicas: 10
  selector:
    matchLabels:
      app: hello-world
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-pod
        image: nigelpoulton/k8sbook:edge
        ports:
        - containerPort: 8080

 

posted @ 2024-06-30 20:55  ~技术小白  阅读(18)  评论(0)    收藏  举报