Kubernetes
Deployments
Inheritance
Container Orchestration
DevOps

Is there a concept of inheritance for Kubernetes deployments?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Kubernetes does not implement object inheritance for Deployments in the way class-based languages do. You cannot define one Deployment as a parent and have another Deployment extend it directly. Instead, reuse is achieved through templating and composition tools such as Kustomize and Helm.

Why Kubernetes Has No Deployment Inheritance

A Deployment is declarative state, not executable code. The API server stores one final object after admission and validation, and controllers reconcile that object toward the desired state. Because of this model, Kubernetes expects each resource manifest to be complete at apply time.

If you need shared configuration across many Deployments, the platform pattern is not inheritance. The platform pattern is generating multiple complete manifests from shared inputs.

Common reuse options are:

  • Kustomize bases and overlays
  • Helm charts and values files
  • Internal generators in CI pipelines

All three produce concrete YAML before objects are applied.

Reuse with Kustomize Bases and Overlays

Kustomize is built into kubectl and works well when you want patch-based customization without a templating language. You define a base Deployment once, then create overlays for each environment.

yaml
1# base/deployment.yaml
2apiVersion: apps/v1
3kind: Deployment
4metadata:
5  name: web-api
6spec:
7  replicas: 2
8  selector:
9    matchLabels:
10      app: web-api
11  template:
12    metadata:
13      labels:
14        app: web-api
15    spec:
16      containers:
17        - name: api
18          image: ghcr.io/example/web-api:1.0.0
19          ports:
20            - containerPort: 8080
yaml
1# overlays/prod/kustomization.yaml
2resources:
3  - ../../base
4patches:
5  - target:
6      kind: Deployment
7      name: web-api
8    patch: |
9      - op: replace
10        path: /spec/replicas
11        value: 5
12      - op: replace
13        path: /spec/template/spec/containers/0/image
14        value: ghcr.io/example/web-api:1.0.3
bash
kubectl apply -k overlays/prod

This gives inheritance-like reuse while staying native to Kubernetes workflows.

Reuse with Helm Values

Helm uses templates and values to render manifests. Think of a chart as a reusable Deployment factory. Environment differences go into separate values files.

yaml
1# values.yaml
2replicaCount: 2
3image:
4  repository: ghcr.io/example/web-api
5  tag: 1.0.0
yaml
1# values-prod.yaml
2replicaCount: 5
3image:
4  tag: 1.0.3
bash
helm upgrade --install web-api ./chart -f values.yaml -f values-prod.yaml

Helm is strong when teams publish reusable app templates across many services.

Building a Safe Promotion Workflow

To keep reuse maintainable, define one base and multiple environment overlays in source control, then promote changes through staged apply commands. This approach gives you a clear audit trail for what changed between test and production.

bash
1# Preview manifests for each stage
2kubectl kustomize overlays/dev > /tmp/dev.yaml
3kubectl kustomize overlays/staging > /tmp/staging.yaml
4kubectl kustomize overlays/prod > /tmp/prod.yaml
5
6# Optional diff before apply
7kubectl diff -f /tmp/staging.yaml
8
9# Apply after review
10kubectl apply -f /tmp/staging.yaml

You can apply the same pattern with Helm by templating each environment and diffing the rendered manifests. The key idea is consistent generation plus review, not direct editing inside the cluster.

Common Pitfalls

One pitfall is trying to copy one Deployment into another with manual duplication. This drifts quickly and makes environment promotion error-prone.

Another problem is mixing Kustomize and Helm without clear ownership. If both tools mutate the same fields, debugging rendered output becomes difficult.

Some teams also overuse patches for large changes. When an overlay patch rewrites most of the base, the base no longer acts as a reusable core. Split into separate bases instead.

Finally, always inspect the rendered output before apply. With Kustomize use kubectl kustomize, and with Helm use helm template. Reviewing final YAML prevents surprises.

Summary

  • Kubernetes Deployments do not support direct inheritance.
  • Reuse is achieved by generating full manifests from shared definitions.
  • Kustomize is good for patch-based environment overlays.
  • Helm is good for parameterized templates and chart reuse.
  • Validate rendered manifests before deployment to reduce config drift.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.