agentleFS
andreab67andreab67/agent-skills/k8s-nextjs-deploy/SKILL.md

k8s-nextjs-deploy

Skill1 starsChanged 2 months agoBSD-3-ClauseView on GitHub

Kubernetes deployment patterns for Next.js applications — Deployment/Service/Ingress manifests, Harbor image pull secrets, Traefik ingress with cert-manager TLS, multi-app namespaces, and K8s secret rotation. Use this skill whenever the user mentions deploying a Next.js app to Kubernetes, ImagePullBackOff, CrashLoopBackOff, Harbor pull secret, Traefik ingress, cert-manager, a missing secretKeyRef, or namespace recovery — even if they just say "the pod won't start" or "deploy this to k8s" without further detail.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do NOT use for:

    line 19
  2. Very specific:

    Add new subdomains to both tls.hosts and rules.

    line 136
  3. Distinctive:

    When managing multiple clusters:

    line 220
  4. Distinctive:

    Always verify context before applying manifests or rotating secrets.

    line 228

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

k8s-nextjs-deploy

Kubernetes deployment patterns for containerized Next.js apps: Harbor registry auth, Traefik ingress with automatic TLS, and multi-app namespace management.

When to use

  • Deploying a new Next.js app (Deployment + Service + Ingress rule)
  • Diagnosing ImagePullBackOff, ErrImagePull, CreateContainerConfigError
  • Rotating Harbor pull secret credentials
  • Adding a subdomain to an existing Traefik ingress with cert-manager
  • Applying K8s manifests after a namespace was deleted
  • Troubleshooting pods stuck because of missing secretKeyRef secrets

Do NOT use for:

  • Non-Kubernetes deployments (Docker Compose, bare-metal, Vercel)
  • Database deployments (stateful sets require separate skill)

Deploying a new Next.js app — step by step

  1. Create the namespace (if it doesn't exist yet): kubectl create namespace <ns>. Success: kubectl get ns <ns> shows Active.
  2. Create the Harbor pull secret using the single-quoted docker-registry command below. Success: kubectl -n <ns> get secret harbor-pull-secret exists and describe shows type kubernetes.io/dockerconfigjson.
  3. Apply the Deployment manifest (with imagePullSecrets, resource requests/limits, and readiness/liveness probes set). Success: kubectl -n <ns> get pods shows the pod Running and 1/1 Ready.
  4. Apply the Service. Success: kubectl -n <ns> get svc <name> shows a ClusterIP with the expected port mapping.
  5. Apply/extend the Ingress, adding the new host to both tls.hosts and rules. Success: kubectl -n <ns> get ingress lists the host, and kubectl -n <ns> get certificate reaches READY: True within a couple of minutes as cert-manager issues the cert.
  6. Verify end-to-end: curl -I https://<host> returns 200/3xx with a trusted TLS chain (no cert warning). If it doesn't, work through Common failure diagnosis below.

Deployment manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cloudreviewer-web
  namespace: cloudreviewer
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cloudreviewer-web
  template:
    metadata:
      labels:
        app: cloudreviewer-web
    spec:
      imagePullSecrets:
        - name: harbor-pull-secret
      containers:
        - name: web
          image: harbor.example.com/project/app:latest
          imagePullPolicy: Always
          securityContext:
            allowPrivilegeEscalation: false
          ports:
            - containerPort: 3000
          resources:
            requests:
              cpu: "100m"
              memory: "128Mi"
            limits:
              cpu: "500m"
              memory: "512Mi"
          env:
            - name: HOSTNAME
              value: "0.0.0.0"
            - name: NODE_ENV
              value: "production"
            - name: NEXT_TELEMETRY_DISABLED
              value: "1"
            - name: OTEL_SERVICE_NAME
              value: "my-app"
            - name: OTEL_EXPORTER_OTLP_ENDPOINT
              value: "http://tempo.tempo.svc.cluster.local:4318"
          readinessProbe:
            httpGet:
              path: /
              port: 3000
          livenessProbe:
            httpGet:
              path: /
              port: 3000

Service

apiVersion: v1
kind: Service
metadata:
  name: cloudreviewer-web
  namespace: cloudreviewer
spec:
  selector:
    app: cloudreviewer-web
  ports:
    - name: http
      port: 80
      targetPort: 3000

Ingress (Traefik + cert-manager)

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: cloudreviewer
  namespace: cloudreviewer
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: traefik
  tls:
    - hosts:
        - www.example.com
        - buy.example.com
        - kb.example.com
      secretName: cloudreviewer-tls
  rules:
    - host: www.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: cloudreviewer-web
                port:
                  number: 80

Add new subdomains to both tls.hosts and rules.

Harbor pull secret

kubectl -n <namespace> create secret docker-registry harbor-pull-secret \
  --docker-server=harbor.example.com \
  --docker-username='robot$project+robot' \
  --docker-password='TOKEN'

Single quotes are mandatory — robot account usernames contain $ which the shell would expand. Never use double quotes.

Rotating credentials

kubectl -n <namespace> delete secret harbor-pull-secret
kubectl -n <namespace> create secret docker-registry harbor-pull-secret \
  --docker-server=harbor.example.com \
  --docker-username='robot$project+robot' \
  --docker-password='NEW_TOKEN'
kubectl -n <namespace> rollout restart deployment/<name>

Pods scheduled before the secret existed cache the auth failure. Always rollout restart after recreating the secret.

Common failure diagnosis

ImagePullBackOff / ErrImagePull

kubectl -n <ns> describe pod <pod> | grep -A 10 "Events:"
Error messageCauseFix
401 UnauthorizedStale or missing pull secretRotate pull secret → rollout restart
repository does not existWrong image name or projectCheck Harbor project name matches image path
no basic auth credentialsPod scheduled before secret createdrollout restart after creating secret

CreateContainerConfigError

Pod image pulled successfully but container won't start — usually a missing secretKeyRef:

kubectl -n <ns> describe pod <pod> | grep -i "secret\|error" | head -20

The referenced secret (e.g., cloudreviewer-buy-secrets) was lost when the namespace was deleted. Recreate it:

kubectl -n <ns> create secret generic my-app-secrets \
  --from-literal=key1=value1 \
  --from-literal=key2=value2

Namespace deleted — full apply order

kubectl apply -f k8s/namespace.yaml
# Recreate the Harbor pull secret and app secrets NOW (commands above) —
# pods created before they exist sit in ImagePullBackOff /
# CreateContainerConfigError and then wait out kubelet back-off.
kubectl apply -f k8s/web-deployment.yaml -f k8s/web-service.yaml
kubectl apply -f k8s/buy-deployment.yaml -f k8s/buy-service.yaml
kubectl apply -f k8s/kb-deployment.yaml  -f k8s/kb-service.yaml
kubectl apply -f k8s/ingress.yaml

Environment variables for Next.js

Required env vars for a standalone Next.js container:

VariableValuePurpose
HOSTNAME0.0.0.0Bind to all interfaces
NODE_ENVproductionEnables prod optimisations
NEXT_TELEMETRY_DISABLED1Disable Next.js telemetry
OTEL_SERVICE_NAMEapp nameOTel trace attribution
OTEL_EXPORTER_OTLP_ENDPOINTTempo/Grafana URLTrace export
NEXT_PUBLIC_SITE_URLhttps://www.example.comMetadata base URL

Multiple kubectl contexts

When managing multiple clusters:

kubectl config get-contexts          # list
kubectl config use-context sr-k8s   # switch
kubectl config current-context      # verify

Always verify context before applying manifests or rotating secrets.

Example prompts

  • "Our pods are stuck in ImagePullBackOff. How do I diagnose and fix this?"
  • "I rotated the Harbor robot account token. How do I update the pull secret without downtime?"
  • "Add subdomain kb.example.com to the existing Traefik ingress."
  • "The namespace got accidentally deleted. Walk me through restoring everything in order."
  • "A pod is in CreateContainerConfigError. What does that mean and how do I fix it?"
  • "Show me a production-ready Next.js Deployment manifest with resource limits and probes."

Related skills

  • nextjs-monorepo-ci — CI pipeline that builds and pushes the images this skill deploys
  • arcgis-enterprise-k8s — deploying a more complex stateful app on Kubernetes

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.