Kubernetes:具有多容器 pod 的 Replicaset 未配置所有容器
Kubernetes: Replicaset with multi-container pod not provisioning all containers
附加图像是我尝试提供的副本集的 yaml 代码,当我执行它时,只有 sync-gcp 容器被提供。我不确定我做错了什么 yaml code of my replicaset
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs
spec:
replicas: 4
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [aws, gcp]}
matchLabels:
version: "2"
template:
metadata:
name: sync-aws
labels:
version: "2"
platform: aws
spec:
containers:
- name: sync-aws
image: schoolofdevops/sync:v2
name: sync-gcp
labels:
version: "2"
platform: gcp
spec:
containers:
- name: sync-gcp
image: schoolofdevops/sync:v2
下面是 replicaset 的 describe 命令的输出
root@kube-01:/vagrant/k8s-code-master/projects/instavote/dev# kubectl
describe rs sync-rs
Name: sync-rs
Namespace: default
Selector: platform in (aws,gcp),version=2
Labels: platform=gcp
version=2
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"apps/v1","kind":"ReplicaSet","metadata":
{"annotations":{},"name":"sync-rs","namespace":"default"},"spec":
{"minReadySeconds"...
Replicas: 4 current / 4 desired
Pods Status: 4 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: platform=gcp
version=2
Containers:
sync-gcp:
Image: schoolofdevops/sync:v2
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-hv25f
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-2689s
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-s54vz
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-jjxm8
root@kube-01:/vagrant/k8s-code-master/projects/instavote/dev#
模板不是列表(所以你要覆盖模板),而你只需要一个模板来创建 pod,然后在 pod 中你将有多个容器。
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs
spec:
replicas: 4
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [aws, gcp]}
matchLabels:
version: "2"
template:
metadata:
name: sync-stuff
lables:
version: "2"
spec:
containers:
- name: sync-aws
image: schoolofdevops/sync:v2
- name: sync-gcp
image: schoolofdevops/sync:v2
但这仍然行不通,因为 aws 和 gcp 需要单独的标签,所以是时候将东西分成单独的 pods 而不是容器了。
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs-aws
spec:
replicas: 2
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [aws]}
matchLabels:
version: "2"
template:
metadata:
name: sync-aws
lables:
version: "2"
platform: "aws"
spec:
containers:
- name: sync-aws
image: schoolofdevops/sync:v2
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs-gcp
spec:
replicas: 2
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [ gcp ]}
matchLabels:
version: "2"
template:
metadata:
name: sync-gcp
lables:
version: "2"
platform: "gcp"
spec:
containers:
- name: sync-gcp
image: schoolofdevops/sync:v2
附加图像是我尝试提供的副本集的 yaml 代码,当我执行它时,只有 sync-gcp 容器被提供。我不确定我做错了什么 yaml code of my replicaset
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs
spec:
replicas: 4
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [aws, gcp]}
matchLabels:
version: "2"
template:
metadata:
name: sync-aws
labels:
version: "2"
platform: aws
spec:
containers:
- name: sync-aws
image: schoolofdevops/sync:v2
name: sync-gcp
labels:
version: "2"
platform: gcp
spec:
containers:
- name: sync-gcp
image: schoolofdevops/sync:v2
下面是 replicaset 的 describe 命令的输出
root@kube-01:/vagrant/k8s-code-master/projects/instavote/dev# kubectl
describe rs sync-rs
Name: sync-rs
Namespace: default
Selector: platform in (aws,gcp),version=2
Labels: platform=gcp
version=2
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"apps/v1","kind":"ReplicaSet","metadata":
{"annotations":{},"name":"sync-rs","namespace":"default"},"spec":
{"minReadySeconds"...
Replicas: 4 current / 4 desired
Pods Status: 4 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
Labels: platform=gcp
version=2
Containers:
sync-gcp:
Image: schoolofdevops/sync:v2
Port: <none>
Host Port: <none>
Environment: <none>
Mounts: <none>
Volumes: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-hv25f
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-2689s
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-s54vz
Normal SuccessfulCreate 36m replicaset-controller Created pod: sync-rs-jjxm8
root@kube-01:/vagrant/k8s-code-master/projects/instavote/dev#
模板不是列表(所以你要覆盖模板),而你只需要一个模板来创建 pod,然后在 pod 中你将有多个容器。
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs
spec:
replicas: 4
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [aws, gcp]}
matchLabels:
version: "2"
template:
metadata:
name: sync-stuff
lables:
version: "2"
spec:
containers:
- name: sync-aws
image: schoolofdevops/sync:v2
- name: sync-gcp
image: schoolofdevops/sync:v2
但这仍然行不通,因为 aws 和 gcp 需要单独的标签,所以是时候将东西分成单独的 pods 而不是容器了。
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs-aws
spec:
replicas: 2
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [aws]}
matchLabels:
version: "2"
template:
metadata:
name: sync-aws
lables:
version: "2"
platform: "aws"
spec:
containers:
- name: sync-aws
image: schoolofdevops/sync:v2
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: sync-rs-gcp
spec:
replicas: 2
minReadySeconds: 20
selector:
matchExpressions:
- {key: platform, operator: In, values: [ gcp ]}
matchLabels:
version: "2"
template:
metadata:
name: sync-gcp
lables:
version: "2"
platform: "gcp"
spec:
containers:
- name: sync-gcp
image: schoolofdevops/sync:v2