【问题标题】:What is the difference between the template section in replicator.yml and pod.yml in Kubernetes?Kubernetes 中replicator.yml 中的template 部分和pod.yaml 有什么区别?
【发布时间】:2016-07-24 22:06:10
【问题描述】:

我试图了解用于启动 Kubernetes 集群的清单文件之间的区别。

假设我有一个名为 pod.yml 的文件定义了我的 pod,也就是运行它的容器:

Pod.yml

apiversion : v1 
 kind: Pod 
 metadata: 
   name : web 
 spec: 
   containers: 
   - name : webserver 
     image : httpd 
     ports : 
      - ContainerPort: 80 
        HostPort: 80`

我有replicator.yml 文件来启动其中的3 个:

复制器.yml

kind: "ReplicationController"
 apiVersion: "v1"
 metadata:
  name: "webserver-controller"
 spec:
  replicas: 3
  selector:
    app: "webserver"
  template:
    spec:
      containers:
        - name: webserver
          image: httpd
          ports:
            - containerPort: 80
              hostport: 80`

如果我已经在使用 pod.yml 来定义用于在 pod 中构建容器的图像,我是否可以避免使用 replication.yml 中的模板部分。 您是否需要所有三个清单文件 pod.yml、service.yml 和replicator.yml 或者您可以只使用service.yml 和replicator.yml 来创建集群。

【问题讨论】:

    标签: docker cloud yaml cluster-computing kubernetes


    【解决方案1】:

    如果您使用的是 ReplicationController、Deployment、DaemonSet 或 Pet Set,则不需要单独的 pod 定义。但是,如果要公开 pod,则应定义服务,这可以在同一个文件中完成。

    例子:

        apiVersion: v1
        kind: Service
        metadata:
          name: default-http-backend
          namespace: default
          labels:
            k8s-app: default-http-backend
        spec:
          ports:
          - port: 80
            targetPort: 8080
            protocol: TCP
            name: http
          selector:
            k8s-app: default-http-backend
        ---
        apiVersion: v1
        kind: ReplicationController
        metadata:
          name: default-http-backend
          namespace: default
        spec:
          replicas: 1
          selector:
            k8s-app: default-http-backend
          template:
            metadata:
              labels:
                k8s-app: default-http-backend
            spec:
              terminationGracePeriodSeconds: 60
              containers:
              - name: default-http-backend
                image: gcr.io/google_containers/defaultbackend:1.0
                livenessProbe:
                  httpGet:
                    path: /healthz
                    port: 8080
                    scheme: HTTP
                  initialDelaySeconds: 30
                  timeoutSeconds: 5
                ports:
                - containerPort: 8080
                resources:
                  limits:
                    cpu: 10m
                    memory: 20Mi
                  requests:
                    cpu: 10m
                    memory: 20Mi
    

    【讨论】:

    • 更准确地说,你不应该创建任何带有元数据的 pod,它与 RepicationController 的选择器匹配,因为 Kubernetes 控制器管理器可能随时删除它。
    猜你喜欢
    • 2013-01-20
    • 2019-03-05
    • 2018-09-29
    • 2021-03-31
    • 2020-05-18
    • 2020-12-27
    • 2018-05-30
    • 2018-03-17
    • 1970-01-01
    相关资源
    最近更新 更多