Back to skills
SKILL.md
Kubernetes Mastery
ASecurityUse when the user asks for a production-ready Helm chart, Helm template helpers, values.schema.json, chart tests, a kubebuilder scaffold, or writing a Kubernetes operator in Go next to a chart. Produces an upgrade-safe chart plus an operator skeleton. Not for operator lifecycle and OLM (use devops-kubernetes-operators) or helmfile releases (use helm-patterns).
- 46 stars
- 0 votes
- 0 copies
- 1 view
- Added November 27, 2026
Works with
Security analysis
100/100npx -y skills add j4flmao/agent-skills --skill kubernetes-mastery --agent claude-codeAre you the author of Kubernetes Mastery?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/j4flmao-kubernetes-mastery)---
name: cloud-native-kubernetes-mastery
description: >
Use when the user asks for a production-ready Helm chart, Helm template helpers, values.schema.json, chart tests, a kubebuilder scaffold, or writing a Kubernetes operator in Go next to a chart. Produces an upgrade-safe chart plus an operator skeleton. Not for operator lifecycle and OLM (use devops-kubernetes-operators) or helmfile releases (use helm-patterns).
version: "2.0.0"
author: "j4flmao"
license: "MIT"
last_verified: "2026-11-17"
tags: [cloud-native, kubernetes, helm, kubebuilder, operators, go]
---
# Kubernetes Mastery: Production Helm Charts and Operator Scaffolding
## Purpose
Ship Kubernetes software that others install safely: a Helm chart whose values are validated and whose upgrades don't break, and — when day-2 automation is needed — a controller-runtime operator scaffolded with kubebuilder.
## Agent Protocol
### Trigger
"kubernetes mastery", "production helm chart", "helm best practices", "helm helpers", "values schema", "kubebuilder", "write an operator in go", "advanced helm templating".
### Input Context
- What is being packaged; target Kubernetes and Helm versions (Helm 3; Helm 4 released Nov 2025 keeps chart API v2).
- Configurability required; whether a CRD/operator is involved.
### Output Artifact
Chart files and/or operator scaffold commands + code. No file unless requested.
### Response Format
```
Chart: {name} apiVersion v2, type application|library
Key templates: {list}
Values validation: values.schema.json
Operator: {group/version/kind} via kubebuilder (if any)
Test: {helm lint, helm template + kubeconform, helm test, envtest}
```
### Completion Criteria
- [ ] `helm lint` and schema validation pass; rendered manifests validated against the target Kubernetes version.
- [ ] Upgrades don't change selector labels or immutable fields.
- [ ] Operator reconciles idempotently and has envtest coverage.
## Helm Chart Layout
```
mychart/
├── Chart.yaml # apiVersion: v2, version (chart SemVer), appVersion
├── values.yaml
├── values.schema.json # JSON Schema; enforced on install/upgrade/lint/template
├── templates/
│ ├── _helpers.tpl
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ └── tests/test-connection.yaml
└── crds/ # installed once, never upgraded/deleted by Helm
```
### Helpers (`_helpers.tpl`)
```yaml
{{- define "mychart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- define "mychart.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name (include "mychart.name" .) | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- define "mychart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mychart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- define "mychart.labels" -}}
helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" }}
{{ include "mychart.selectorLabels" . }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
```
Selector labels must never include the version: `spec.selector` of a Deployment is immutable.
### Deployment with config-change rollout
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mychart.fullname" . }}
labels: {{- include "mychart.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels: {{- include "mychart.selectorLabels" . | nindent 6 }}
template:
metadata:
labels: {{- include "mychart.selectorLabels" . | nindent 8 }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
spec:
containers:
- name: app
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
ports:
- name: http
containerPort: {{ .Values.service.targetPort }}
{{- with .Values.resources }}
resources: {{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.securityContext }}
securityContext: {{- toYaml . | nindent 12 }}
{{- end }}
```
- Omit `replicas` when an HPA manages scale, otherwise every upgrade resets it.
- `checksum/config` restarts pods when the ConfigMap changes.
- Use `required "image.repository is required" .Values.image.repository` for mandatory values.
### Values schema (excerpt)
```json
{
"$schema": "https://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["image", "service"],
"properties": {
"replicaCount": { "type": "integer", "minimum": 1 },
"image": {
"type": "object",
"required": ["repository"],
"properties": {
"repository": { "type": "string", "minLength": 1 },
"tag": { "type": "string" },
"pullPolicy": { "enum": ["Always", "IfNotPresent", "Never"] }
}
},
"service": {
"type": "object",
"properties": { "targetPort": { "type": "integer", "minimum": 1, "maximum": 65535 } }
}
}
}
```
### Chart validation pipeline
```bash
helm lint ./mychart --strict
helm template rel ./mychart -f ci/values-prod.yaml | kubeconform -strict -kubernetes-version 1.33.0 -summary
helm install rel ./mychart --dry-run=server # validates against the live API server
helm test rel # runs templates/tests/* hooks
```
## Operator Scaffold (kubebuilder)
```bash
kubebuilder init --domain example.com --repo github.com/example/cache-operator
kubebuilder create api --group cache --version v1alpha1 --kind Cache --resource --controller
make manifests generate # CRD YAML + DeepCopy from Go markers
make test # envtest: real kube-apiserver + etcd binaries
make docker-build docker-push IMG=registry.example.com/cache-operator:v0.1.0
make deploy IMG=registry.example.com/cache-operator:v0.1.0
```
API types with validation markers:
```go
type CacheSpec struct {
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=9
Replicas int32 `json:"replicas"`
// +kubebuilder:validation:Pattern=`^\d+\.\d+\.\d+$`
Version string `json:"version"`
}
type CacheStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
type Cache struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec CacheSpec `json:"spec,omitempty"`
Status CacheStatus `json:"status,omitempty"`
}
```
The reconcile loop itself (get → build desired → create/update → status conditions) is shown in `skills/devops/kubernetes-operators/references/merged-cloud-native-k8s-operators.md`. Generated RBAC comes from `// +kubebuilder:rbac:groups=...` markers above `Reconcile`.
## Shipping an Operator with Helm
- Put CRDs in `crds/` only if you accept that Helm never upgrades them; otherwise template CRDs (with `helm.sh/resource-policy: keep`) or manage them separately.
- Pin operator image by digest in production values.
## Anti-Patterns
- Version label in selectors; `latest` image tags.
- Giant `values.yaml` with no schema → silent typos (`replicacount`).
- Using `lookup` for core logic (returns empty during `helm template`/dry-run client).
- Generating secrets with `randAlphaNum` on every upgrade (rotates passwords, breaks apps, and causes GitOps drift).
- Deprecated API versions in templates; use `.Capabilities.APIVersions.Has` only for genuinely optional APIs.
## Checklist
- [ ] Standard helpers and `app.kubernetes.io/*` labels.
- [ ] `values.schema.json` covers required fields and enums.
- [ ] kubeconform against target K8s versions in CI.
- [ ] Operator: markers for validation/status subresource, envtest, leader election on.
- [ ] Chart and app versions bumped independently (SemVer).
## References
- Related skills: `skills/devops/helm-patterns/SKILL.md`, `skills/devops/kubernetes-operators/references/merged-cloud-native-k8s-operators.md`, `skills/devops/kubernetes-operators/SKILL.md`.
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.