node规划

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
node: 
按照业务节点划分
app=wanka app=wukong
按照功能区分
: app=nginx
按照性能区分
: disk=ssd

结论: 部署首先选择节点属于那个业务还是需要属于公共的服务或者还需要特殊的性能如ssd
使用节点亲和性判断:
# 节点亲和性
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-test-affinity
spec:
  replicas: 3
  selector:
    matchLabels:
      app: tomcat-t-a
  template:
    metadata:
      labels:
        app: tomcat-t-a
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: beta.kubernetes.io/arch
                operator: In
                values:
                - amd64
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 1
            preference:
              matchExpressions:
              - key: disktype
                operator: NotIn
                values:
                - ssd

POD规划

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
规划好节点之后,pod是否运行在同一台node上,还需规划。
pod的亲和性表达方式与Node亲和性是一样的表达方式。

多个pod运行在一台/或者一组node上、或者禁止运行在一个节点上、或者分区多个可用区去部署。
requiredDuringSchedulingIgnoredDuringExecution      # 必须满足的
preferredDuringSchedulingIgnoredDuringExecution     # 尽量满足的

kubernetes内置标签: topologyKey, 此处功能类似拓扑
    ○ kubernetes.io/hostname
    ○ failure-domain.beta.kubernetes.io/zone
    ○ failure-domain.beta.kubernetes.io/region
    ○ beta.kubernetes.io/instance-type
    ○ beta.kubernetes.io/os
    ○ beta.kubernetes.io/arch

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-schedule
spec:
  replicas: 5
  selector:
    matchLabels:
      app: tomcat-schedule
  template:
    metadata:
      labels:
        app: tomcat-schedule
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: app
                  operator: In
                  values:
                  - tomcat-schedule
              topologyKey: failure-domain.beta.kubernetes.io/zone
      containers:
      - name: tomcat
        image: tomcat
        ports:
        - containerPort: 8080