What is the difference between the template section in replicator.yml and pod.yml in Kubernetes?

7/24/2016

I'm trying to understand the difference between the manifest files used for bringing up the Kubernetes cluster.

Say suppose I have a file called pod.yml that defines my pod, that is the containers running it:

Pod.yml

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

And I have replicator.yml file to launch 3 of these pods:

Replicator.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`

Can I avoid the template section in the replicator.yml if I'm already using pod.yml to define the images to be used to build the containers in the pod. Do you need all three manifest files pod.yml, service.yml and replicator.yml or can you just use service.yml and replicator.yml to create the cluster.

-- Noob333
cloud
cluster-computing
docker
kubernetes
yaml

1 Answer

7/25/2016

If you are using a ReplicationController, Deployment, DaemonSet or a Pet Set, you don't need a separate pod definition. However, the service should be defined if you want to expose the pod and this can be done on the same file.

Example:

    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
-- Camil
Source: StackOverflow