A Guide to Different Types of Resources for Deploying Pods in Kubernetes

Matías Salinas
4 min readMar 16, 2023

--

Kubernetes is an open-source container orchestration platform that is widely used for automating deployment, scaling, and management of containerized applications. One of the fundamental concepts of Kubernetes is Pods, which are the smallest deployable units in the platform. Pods can be deployed using different types of resources, each with its advantages and disadvantages. In this article, we will explore the various types of resources for deploying Pods in Kubernetes and their functionalities.

Deployment

Deployments are a Kubernetes resource that provides declarative updates to Pods and ReplicaSets. They allow you to define the desired state of your application and manage the deployment process. Deployments are typically used for stateless applications and can be scaled up or down using the kubectl command-line tool or Kubernetes API.

Advantages:

  • Allows you to specify the desired state of your application and ensures that it remains in that state.
  • Provides rolling updates, which minimize downtime during the deployment process.
  • Enables you to scale up or down your application as per the requirement.

Example of Deployment resource:

apiVersion: apps/v1
kind: Deployment
metadata:
name: example-deployment
spec:
replicas: 3
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-container
image: example/image:latest
ports:
- containerPort: 80

StatefulSet

StatefulSets are a Kubernetes resource that is used to manage stateful applications that require persistent storage. They allow you to create and manage a set of Pods that have unique identities, and each Pod maintains its state even after it is terminated or restarted. StatefulSets are typically used for stateful applications such as databases, where data persistence is crucial.

Advantages:

  • Provides unique identities for each Pod, which is essential for stateful applications.
  • Enables you to manage the lifecycle of stateful applications.
  • Ensures that the stateful applications maintain their state even after they are terminated or restarted.

Example of StatefulSet resource:

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: example-statefulset
spec:
replicas: 3
serviceName: example-service
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-container
image: example/image:latest
ports:
- containerPort: 80
volumeMounts:
- name: example-volume
mountPath: /data
volumeClaimTemplates:
- metadata:
name: example-volume
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi

ReplicaSet

ReplicaSets are a Kubernetes resource that ensures that a specified number of replicas of a Pod are running at any given time. They are typically used for stateless applications and can be scaled up or down based on demand. ReplicaSets are an upgrade from Replication Controllers and offer more advanced features.

Advantages:

  • Ensures that a specified number of replicas of a Pod are running at any given time.
  • Provides rolling updates, which minimize downtime during the deployment process.
  • Enables you to scale up or down your application as per the requirement.

Example of ReplicaSet resource:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: example-replicaset
spec:
replicas: 3
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-container
image: example/image:latest
ports:
- containerPort: 80

This ReplicaSet resource creates and maintains three replicas of a Pod that matches the app: example-app label selector. The Pod specification is defined in the template section of the resource. The replicas field specifies the desired number of replicas, and the selector field selects the Pods that the ReplicaSet manages.

DaemonSet

DaemonSets are a Kubernetes resource that ensures that a specified Pod runs on all or a subset of nodes in a cluster. They are typically used for running system daemons, such as log collectors, on all or a specific set of nodes in a cluster. DaemonSets are particularly useful in scenarios where you need to deploy a system-level agent on every node in a Kubernetes cluster.

Advantages:

  • Ensures that a specified Pod runs on all or a subset of nodes in a cluster.
  • Useful for running system daemons on all or a specific set of nodes in a cluster.
  • Allows you to deploy a system-level agent on every node in a Kubernetes cluster.

Example of DaemonSet resource:

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: example-daemonset
spec:
selector:
matchLabels:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-container
image: example/image:latest
ports:
- containerPort: 80

This DaemonSet resource ensures that a Pod with the app: example-app label runs on all or a subset of nodes in a cluster. The Pod specification is defined in the template section of the resource. The selector field selects the nodes that the DaemonSet manages.

ReplicationController (RC)

ReplicationController (RC) is a Kubernetes resource that ensures a specified number of replicas of a Pod are running at all times. It is an older resource that has been replaced by ReplicaSets, but it is still supported for backward compatibility.

Advantages:

  • Ensures that a specified number of replicas of a Pod are running at all times.
  • Provides rolling updates, which minimize downtime during the deployment process.
  • Enables you to scale up or down your application as per the requirement.

Example of ReplicationController resource:

apiVersion: v1
kind: ReplicationController
metadata:
name: example-rc
spec:
replicas: 3
selector:
app: example-app
template:
metadata:
labels:
app: example-app
spec:
containers:
- name: example-container
image: example/image:latest
ports:
- containerPort: 80

This ReplicationController resource creates and maintains three replicas of a Pod that matches the app: example-app label selector. The Pod specification is defined in the template section of the resource. The replicas field specifies the desired number of replicas, and the selector field selects the Pods that the ReplicationController manages.

you after reading this…

--

--

Matías Salinas
Matías Salinas

No responses yet