Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure a Kubernetes Multi-Pod Deployment

I would like to deploy an application cluster by managing my deployment via k8s Deployment object. The documentation has me extremely confused. My basic layout has the following components that scale independently:

  1. API server
  2. UI server
  3. Redis cache
  4. Timer/Scheduled task server

Technically, all 4 above belong in separate pods that are scaled independently.

My questions are:

  1. Do I need to create pod.yml files and then somehow reference them in deployment.yml file or can a deployment file also embed pod definitions?
  2. K8s documentation seems to imply that the spec portion of Deployment is equivalent to defining one pod. Is that correct? What if I want to declaratively describe multi-pod deployments? Do I do need multiple deployment.yml files?
like image 325
Raj Avatar asked Apr 04 '17 20:04

Raj


People also ask

Can a Kubernetes deployment have multiple pods?

A Deployment is meant to represent a single group of PODs fulfilling a single purpose together. You can have many Deployments work together in the virtual network of the cluster. For accessing a Deployment that may consist of many PODs running on different nodes you have to create a Service.

How do you use multiple pods in Kubernetes?

If you need to run a single container in Kubernetes, then you have to create a pod for it which is nothing but Single Container Pod. If you have to run two or more containers in a pod, then the pod created to place these containers is called a Multi Container Pod.

How do I deploy multiple Yaml files in Kubernetes?

Using Helm, you can deploy multiple resources (bunch of YAMLs) in one go. Helm Charts help you define, install, and upgrade even the most complex Kubernetes application. Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources.


2 Answers

Pagids answer has most of the basics. You should create 4 Deployments for your scenario. Each deployment will create a ReplicaSet that schedules and supervises the collection of PODs for the Deployment.

Each Deployment will most likely also require a Service in front of it for access. I usually create a single yaml file that has a Deployment and the corresponding Service in it. Here is an example for an nginx.yaml that I use:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
  name: nginx
  labels:
    app: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    name: nginx
    targetPort: 80
    nodePort: 32756
  selector:
    app: nginx
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginxdeployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginxcontainer
        image: nginx:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 80

Here some additional information for clarification:

  • A POD is not a scalable unit. A Deployment that schedules PODs is.
  • A Deployment is meant to represent a single group of PODs fulfilling a single purpose together.
  • You can have many Deployments work together in the virtual network of the cluster.
  • For accessing a Deployment that may consist of many PODs running on different nodes you have to create a Service.
  • Deployments are meant to contain stateless services. If you need to store a state you need to create StatefulSet instead (e.g. for a database service).
like image 92
Oswin Noetzelmann Avatar answered Oct 17 '22 15:10

Oswin Noetzelmann


You can use the Kubernetes API reference for the Deployment and you'll find that the spec->template field is of type PodTemplateSpec along with the related comment (Template describes the pods that will be created.) it answers you questions. A longer description can of course be found in the Deployment user guide.

To answer your questions...

1) The Pods are managed by the Deployment and defining them separately doesn't make sense as they are created on demand by the Deployment. Keep in mind that there might be more replicas of the same pod type.

2) For each of the applications in your list, you'd have to define one Deployment - which also makes sense when it comes to difference replica counts and application rollouts.

3) you haven't asked that but it's related - along with separate Deployments each of your applications will also need a dedicated Service so the others can access it.

like image 45
pagid Avatar answered Oct 17 '22 17:10

pagid