Kubernetes:带有多容器容器的Replicaset未置备所有容器

时间:2018-10-17 19:15:19

标签: kubernetes replicaset

附加的图像是我要配置的副本集的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 

下面是副本集的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#

1 个答案:

答案 0 :(得分:1)

模板不是列表(因此您要覆盖模板),相反,您只需要一个模板即可创建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使用单独的标签,因此需要将它们分为单独的容器而不是容器的时间。

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