✦ For everyone, free.

Practical knowledge for real and everyday life

Home

Kubernetes Package Resource Organization

Kubernetes Package Resource Organization manages containerized apps with declarative manifests, ensuring scalable and consistent cluster deployments.

Kubernetes Package Resource Organization is the practice of deciding how manifests within a package are split across files and directories, whether grouped by resource kind, by application component, or by deployment layer, and how consistent naming and labeling conventions keep a growing package navigable as the number of resources it contains increases.


Organizing by Resource Kind

One File Type Per Category

chart/
  templates/
    deployments.yaml
    services.yaml
    configmaps.yaml
    ingress.yaml

Grouping by kind keeps all Deployment definitions together, all Service definitions together, and so on, which suits a small package with only a handful of resources per kind, but scales poorly once a package manages many independent components, since understanding a single component then requires jumping across several files.


Organizing by Application Component

One Directory Per Logical Service

chart/
  templates/
    web/
      deployment.yaml
      service.yaml
    worker/
      deployment.yaml
      configmap.yaml
    database/
      statefulset.yaml
      service.yaml

Grouping by component instead keeps every resource belonging to a single logical piece of the application together, which scales better for multi-component packages since understanding or modifying "the worker" means opening one directory rather than searching across kind-based files for anything labeled worker.

Files Touched Components Changed , not Kinds Changed

Organizing by Deployment Layer

Separating Infrastructure From Application

manifests/
  00-namespace/
  10-rbac/
  20-crds/
  30-infrastructure/
  40-application/

A numerically prefixed, layered directory structure encodes both organizational grouping and an implicit apply-order hint, useful in raw manifest or Kustomize-based packaging where no dependency graph is computed automatically, making the intended sequence visible directly from directory listing order.

for dir in manifests/*/; do kubectl apply -f "$dir"; done

Naming Conventions

Consistent, Predictable Resource Names

metadata:
  name: {{ .Release.Name }}-web-deployment

Adopting a consistent naming pattern, release name prefix followed by component and kind suffix, makes resources from the same release trivially identifiable and groupable via kubectl get all -l release={{ .Release.Name }} regardless of how many distinct kinds a release actually contains.

File Naming Mirrors Resource Naming

templates/
  web-deployment.yaml
  web-service.yaml
  worker-deployment.yaml

Naming files after the resource they define, rather than generically (deployment1.yaml, service2.yaml), lets a reader locate a specific manifest by name alone without opening every file, an easily overlooked but high-leverage convention as a package grows past a handful of files.


Label-Based Grouping as a Complement to File Structure

Standard Labels for Cross-Cutting Queries

metadata:
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/component: web
    app.kubernetes.io/part-of: myapp
    app.kubernetes.io/managed-by: helm

Regardless of how files are organized on disk, consistent application of the recommended Kubernetes labels lets any component's full resource set be queried directly from the cluster, decoupling the query-time grouping (by label) from the authoring-time grouping (by file structure), which need not match each other exactly.

kubectl get all -l app.kubernetes.io/component=web

Scaling Organization With Package Size

When to Split a Monolithic Package Into Subcharts or Sub-Bases

dependencies:
  - name: web-component
    version: "1.0.0"
  - name: worker-component
    version: "1.0.0"

Once a package's resource count and independent-versioning needs grow large enough, splitting what was a single chart's templates/ directory into independently versioned subcharts (or, for Kustomize, independently maintained bases composed via a top-level overlay) trades some coordination overhead for the ability to release, test, and reuse each component independently of the others.


Relationship to the Packaging Model and Raw Manifest Packaging

Resource organization is the authoring-time counterpart to the template-values-render structure described in the broader packaging model: a well-organized package makes navigating and modifying the template half of that model tractable as complexity grows, and the same organizational principles, kind versus component versus layer grouping, apply whether the underlying mechanism is a Helm chart's templates, a Kustomize base's resources, or, at the simplest end, the directory structure of raw manifest packaging with no tooling involved at all.

web/ deployment.yaml service.yaml worker/ deployment.yaml database/ statefulset.yaml