 其他控制器(DS、RC和RS)
其他控制器(DS、RC和RS)
  # 其他控制器 yaml文件常用配置项
包含 DaemonSet(DS)、ReplicationController(RC)和 ReplicaSet(RS)。
这三种控制器无法直接通过命令行创建,你需要先生成一个 Deployment 的配置文件,然后对其进行修改。
学习更多
# 1创建 DaemonSet(DS)
kubectl create deployment ds-test --image nginx --dry-run=client -o yaml > ds-test.yaml
vim ds-test.yaml
1
2
3
2
3
修改四个不同点:
- 将kind字段改为DaemonSet
- DaemonSet 没有 “副本数” 这个概念,因为每个节点上至多只有一个 Pod,所以删除spec.replicas字段
- 删除spec.strategy字段
- 删除最后一行的status字段
apiVersion: apps/v1
kind: DaemonSet                 # 修改资源名称
metadata:
  creationTimestamp: null
  labels:
    app: ds-test
  name: ds-test
spec:                           # 删除副本数 replicas 和策略 strategy
  selector:
    matchLabels:
      app: ds-test
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: ds-test
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
# 删除 status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 2创建 ReplicationController(RC)
kubectl create deployment rc-test --image nginx --dry-run=client -o yaml > rc-test.yaml
vim rc-test.yaml
1
2
3
2
3
修改四个不同点:
- RC 的apiVersion应该为v1
- 对应的kind(资源名称)
- RC 的spec.selector字段下没有matchLabels字段,可以直接填写标签
- 没有spec.strategy字段
# apiVersion: apps/v1
# kind: Deployment
apiVersion: v1
kind: ReplicationController
metadata:
  creationTimestamp: null
  labels:
    app: rc-test
  name: rc-test
spec:
  replicas: 1
  selector:
    # matchLabels:              没有该字段
    app: rc-test
  # strategy: {}                没有该字段
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: rc-test
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
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
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
# 3创建 ReplicaSet(RS)
kubectl create deployment rs-test --image nginx --dry-run=client -o yaml > rs-test.yaml
vim rs-test.yaml
1
2
3
2
3
修改两个不同点:
- 修改资源名称kind
- 删除字段spec.strategy
apiVersion: apps/v1
kind: ReplicaSet                # 资源名称
metadata:
  creationTimestamp: null
  labels:
    app: rs-test
  name: rs-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rs-test
  # strategy: {}                # 没有该字段
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: rs-test
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
编辑  (opens new window)
  