一个容器多个进程,一个pod多个容器

  1. 一个容器多个进程:在Docker的镜像编译脚本Dockerfile中带起多个进程,如下可以在contivNet.sh中启动多个进程
FROM 192.168.1.2:5001/world/centos7/ovs-2.6.4:1


COPY ./bin /contiv/bin/
COPY ./scripts /contiv/scripts/

ENTRYPOINT ["/contiv/scripts/contivNet.sh"]
  1. 一个pod多个容器,可以在yaml文件中如下设置,在containers 中定义两个容器
# each master and worker node in a Kubernetes cluster.
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
  name: contiv-netplugin-ovs
  namespace: kube-system
  labels:
    k8s-app: contiv-netplugin
spec:
  updateStrategy:
    type: OnDelete
  selector:
    matchLabels:
      k8s-app: contiv-netplugin
  template:
    metadata:
      labels:
        k8s-app: contiv-netplugin
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/port: '9004'
        scheduler.alpha.kubernetes.io/critical-pod: ''
    spec:
      hostNetwork: true
      hostPID: true
      nodeSelector:
        node-role.kubernetes.io/node: ""
        node-network-driver: "ovs"
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      serviceAccountName: contiv-netplugin
      containers:
        - name: netplugin-exporter
          image: 192.168.1.2:5001/contiv/exporter:0.1
          env:
            - name: CONTIV_ETCD
              valueFrom:
                configMapKeyRef:
                  name: contiv-config
                  key: contiv_etcd
            - name: CONTIV_ROLE
              value: 'ovs-netplugin'
          volumeMounts:
            - mountPath: /k8s_log/contiv
              name: var-log-contiv-exporter
              readOnly: false
        - name: contiv-netplugin
          image: 192.168.1.2:5001/contiv/netplugin:1.2.0_6.3
          env:
            - name: CONTIV_ROLE
              value: netplugin
            - name: CONTIV_NETPLUGIN_VLAN_UPLINKS
              value: enp130s0f0
            - name: CONTIV_NETPLUGIN_DRIVER
              value: ovs
            - name: CONTIV_NETPLUGIN_LOG_LEVEL
              value: INFO
            - name: CONTIV_NETPLUGIN_MODE
              valueFrom:
                configMapKeyRef:
                  name: contiv-config
                  key: contiv_mode
            - name: CONTIV_NETPLUGIN_VTEP_IP
              valueFrom:

可以在每个容器中启动一个进程,例如可以使用command启动进程:

 command:
 - /bin/sh
 - -c
 - /kubemark --morph=kubelet --name=$(NODE_NAME)  --kubeconfig=/kubeconfig/kubelet-$(NODE_NAME).kubeconfig $(CONTENT_TYPE) --alsologtostderr --v=4

这样一个pod中启动了两个容器,每个容器启动了一个进程。

原文地址:https://www.cnblogs.com/janeysj/p/11721409.html