Exactly one Pod

8/21/2019

I'm working on deploying the Thanos monitoring system and one of its components, the metric compactor, warns that there should never be more than one compactor running at the same time. If this constraint is violated it will likely lead to corruption of metric data.

Is there any way to codify "Exactly One" pod via Deployment/StatefulSet/etc, aside from "just set replicas: 1 and never scale"? We're using Rancher as an orchestration layer and it's real easy to hit that + button without thinking about it.

-- Sammitch
kubernetes
rancher

2 Answers

8/21/2019

Limit the replicas in your deployment to 1

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-app
spec:
  replicas: 1
-- Charlie
Source: StackOverflow

8/21/2019

Be careful with Deployment, because they can be configured with two update strategy:

  • RollingUpdate: new pods are added while and old pods are terminated. This mean that, depending on the maxSurge option, if you set your replicas to 1, you may still be have at most 2 pods.
  • Recreate: all the previous pods are terminated before any new pods are created.

Instead, Statefulsets guarantee that there will never be more than 1 instance of a pod at any given time.

apiVersion: apps/v1beta1
kind: StatefulSet
spec:
  replicas: 1

Unlike Deployments, pods are not replaced until the previous has been terminated.

-- Federkun
Source: StackOverflow