Kubernetes Stateful Deployments

The Challenge

A Solution

  • We introduce two Pod annotations; one specifies a volume name and the other its size
  • The solution creates a PersistentVolumeClaim unique to the Deployment’s Pod and sized to the volume size annotation. It is also labeled with key managed and value true
  • It then updates the Pod’s volume named with the volume name annotation to reference the PersistentVolumeClaim; here replacing the emptyDir with the PersistentVolumeClaim
  • It also updates the Pod’s labels with key volume-claim/name; the value being the PersistentVolumeClaim’s name
  • If the mutating admission webhook creates a PersistentVolumeClaim but the Pod is not persisted, the controller deletes the PersistentVolumeClaim
  • Watches for Pod deletions and deletes the associated PersistentVolumeClaims created by the mutating admission webhook




Broad infrastructure, development, and soft-skill background

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

REST: A Beginner’s guide

How to Simplify Monitoring for Modern Applications

Using More Complex Regexes with Python

How I installed Ubuntu 16.04.1 LTS on an old MacBook 2.0 GHz Core 2 Duo (T7200)


General DevOps Interview Questions

Dark Matter DeFi Updated RoadMap — 2022

Gradle and Bazel: A Song of Ice and Fire

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
John Tucker

John Tucker

Broad infrastructure, development, and soft-skill background

More from Medium

A relative between local environment and Kubernetes

Monitoring multiple OKE clusters with Prometheus, Thanos and Grafana — Part 2

Is Kubernetes a DIY platform?