System DesignDevOps

Advanced Kubernetes: Helm, Gateway API and Autoscaling

· Pavan Y N · kubernetes, devops, containers, scalability

Once a cluster runs Deployments and Services, three problems show up quickly: repeating the same manifests for every environment, routing external HTTP traffic into the cluster, and adjusting capacity as load changes. EduGeek explains how Helm, the Gateway API (and the older Ingress API), and the Horizontal Pod Autoscaler address them, with manifests checked against Kubernetes 1.35 through 1.37. If Deployments and Services are unfamiliar, start with Kubernetes Fundamentals.

# Helm: the Kubernetes package manager

Helm packages Kubernetes manifests as charts, renders them from templates and values, and tracks each installation as a versioned release.

## Why Helm?

  • →Templating: one chart, many environments, driven by values files
  • →Versioning: every install and upgrade creates a numbered release revision
  • →Rollback: return to an earlier revision with one command
  • →Dependencies: charts can depend on other charts
  • →Sharing: distribute charts through repositories and OCI registries

## Installing Helm

Helm 4 is the current major version, and the installation page now documents the get-helm-4 script. Download the script, read it, and then run it, instead of piping it straight into a shell:

code
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-4
chmod 700 get_helm.sh
./get_helm.sh

helm version

Package managers such as Homebrew, Scoop, Winget, and apt also provide Helm, although the Helm project does not maintain those packages.

## Creating a Helm chart

code
helm create myapp

A generated chart looks like this:

code
myapp/
├── Chart.yaml           # Chart metadata
├── values.yaml          # Default values
├── .helmignore
└── templates/           # Kubernetes manifest templates
    ├── _helpers.tpl
    ├── deployment.yaml
    ├── service.yaml
    ├── serviceaccount.yaml
    ├── hpa.yaml
    ├── ingress.yaml
    ├── httproute.yaml
    ├── NOTES.txt
    └── tests/

A charts/ directory appears only after a chart declares dependencies. Recent versions of helm create also generate an httproute.yaml template alongside ingress.yaml.

## Chart.yaml example

code
apiVersion: v2
name: myapp
description: My application Helm chart
type: application
version: 1.0.0
appVersion: "1.0.0"

version is the chart's own version, and appVersion is the version of the application it deploys.

## values.yaml example

code
replicaCount: 3

image:
  repository: myapp
  tag: ""            # defaults to the chart's appVersion
  pullPolicy: IfNotPresent

containerPort: 8080

service:
  type: ClusterIP
  port: 80

resources:
  limits:
    cpu: 500m
    memory: 512Mi
  requests:
    cpu: 250m
    memory: 256Mi

## Template example

Use the recommended app.kubernetes.io/* labels, and include the release name in the selector. A selector that uses only the chart name makes two releases of the same chart in one namespace select each other's pods.

code
# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}
  labels:
    app.kubernetes.io/name: {{ .Chart.Name }}
    app.kubernetes.io/instance: {{ .Release.Name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ .Chart.Name }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ .Chart.Name }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - containerPort: {{ .Values.containerPort }}
        resources:
          {{- toYaml .Values.resources | nindent 10 }}
code
# templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-{{ .Chart.Name }}
spec:
  type: {{ .Values.service.type }}
  selector:
    app.kubernetes.io/name: {{ .Chart.Name }}
    app.kubernetes.io/instance: {{ .Release.Name }}
  ports:
  - port: {{ .Values.service.port }}
    targetPort: {{ .Values.containerPort }}

## Helm commands

code
# Check the chart and preview the rendered manifests
helm lint ./myapp
helm template myapp ./myapp

# Install a chart
helm install myapp ./myapp

# Install with custom values
helm install myapp ./myapp -f custom-values.yaml

# Upgrade a release, or install it if it does not exist yet
helm upgrade --install myapp ./myapp

# Roll back to revision 1
helm rollback myapp 1

# List releases
helm list

# Show release history (revisions)
helm history myapp

# Uninstall a release
helm uninstall myapp

Helm 4 renamed two flags. --atomic is now --rollback-on-failure, and --force is now --force-replace. The old names still work but print a deprecation warning. --rollback-on-failure on helm upgrade rolls back to the previous successful release if the upgrade fails. Helm 4 also applies manifests with server-side apply by default for new installs, while upgrades keep the apply method the release already used.

# Exposing HTTP services: Ingress and Gateway API

## The state of Ingress

The Ingress API (networking.k8s.io/v1) is generally available, but it is frozen. The Kubernetes documentation recommends the Gateway API instead and states that Ingress receives no further development, although there are no plans to remove it.

Ingress NGINX, the community Ingress controller maintained by the Kubernetes project, has been retired. SIG Network and the Security Response Committee announced in November 2025 that best-effort maintenance would end in March 2026, with no further releases, bug fixes, or security updates afterward. Existing installations keep running, but they no longer receive fixes. This is a different project from F5's NGINX Ingress Controller and from the NGINX web server. Older tutorials installed it with helm install ... ingress-nginx/ingress-nginx. New clusters should not.

## An Ingress resource

Ingress remains valid for existing clusters and for controllers that still support it. It needs a controller that matches the ingressClassName.

code
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp-ingress
spec:
  ingressClassName: example-class   # the IngressClass of the controller in your cluster
  tls:
  - hosts:
    - myapp.example.com
    secretName: myapp-tls
  rules:
  - host: myapp.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: myapp-service
            port:
              number: 80
      - path: /api
        pathType: Prefix
        backend:
          service:
            name: api-service
            port:
              number: 8080

Controller-specific behavior, such as URL rewrites, lives in annotations that differ between controllers. An annotation copied from one controller's documentation can silently change routing on another. For example, nginx.ingress.kubernetes.io/rewrite-target: /, used in older versions of this example, rewrote every request path to /, which breaks the /api rule above.

## Gateway API

The Gateway API is a set of custom resources, installed as an add-on, that split responsibilities between roles. Infrastructure providers define a GatewayClass, cluster operators create a Gateway with listeners, and application teams attach HTTPRoute objects. GatewayClass, Gateway, HTTPRoute, and GRPCRoute are the long-stable kinds, and later releases have promoted more routes (Gateway API v1.6 moved TCPRoute and UDPRoute to the standard channel). Header matching and traffic weighting are part of the API rather than controller annotations.

Install the standard-channel CRDs, then a controller that implements the API:

code
kubectl apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.6.1/standard-install.yaml

The Gateway API project lists conformant controllers, including Envoy Gateway, Istio, Cilium, Traefik Proxy, and NGINX Gateway Fabric. Each controller provides its own GatewayClass name.

code
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: public-gateway
spec:
  gatewayClassName: example-class   # provided by your Gateway controller
  listeners:
  - name: https
    protocol: HTTPS
    port: 443
    hostname: "*.example.com"
    tls:
      mode: Terminate
      certificateRefs:
      - kind: Secret
        name: wildcard-tls
    allowedRoutes:
      namespaces:
        from: Same
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: myapp
spec:
  parentRefs:
  - name: public-gateway
  hostnames:
  - "myapp.example.com"
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /api
    backendRefs:
    - name: api-service
      port: 8080
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: myapp-service
      port: 80

## Multiple host routing

Host-based routing attaches one route per hostname to the same Gateway:

code
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: app1
spec:
  parentRefs:
  - name: public-gateway
  hostnames:
  - "app1.example.com"
  rules:
  - backendRefs:
    - name: app1-service
      port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: app2
spec:
  parentRefs:
  - name: public-gateway
  hostnames:
  - "app2.example.com"
  rules:
  - backendRefs:
    - name: app2-service
      port: 80

By default, a Gateway accepts routes only from its own namespace. Routes in other namespaces require a matching allowedRoutes setting on the listener.

To migrate existing Ingress objects, the Kubernetes project released Ingress2Gateway 1.0 in March 2026 to convert Ingress resources into Gateway API resources.

# Horizontal Pod Autoscaling (HPA)

The Horizontal Pod Autoscaler changes the replica count of a Deployment, StatefulSet, or similar workload. A control loop, running every 15 seconds by default, compares observed metrics with targets and computes desiredReplicas = ceil(currentReplicas × currentMetricValue / desiredMetricValue).

## Metrics Server installation

Resource metrics (CPU and memory) come from the metrics.k8s.io API, which Metrics Server provides. It is not installed by default in every cluster.

code
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml

Metrics Server requires the API aggregation layer, and the kubelet certificates must be signed by the cluster CA. Clusters with self-signed kubelet certificates, such as many local test clusters, need the --kubelet-insecure-tls flag, which the project marks as for testing purposes only. The project also states that Metrics Server is meant only for autoscaling, not as an accurate source of resource usage for monitoring.

## CPU-based autoscaling

Utilization targets are a percentage of each container's resource request. If a container in the pod has no CPU request, the autoscaler takes no action for that metric, so set requests on the target workload first.

code
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

## Memory-based autoscaling

code
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp-memory-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 2
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80

Memory only works as a scaling signal when an application's memory use falls after load falls. Applications whose runtimes hold on to memory may never scale back down this way.

## Scaling on one container

When a pod has a sidecar, pod-level utilization mixes the containers together. The ContainerResource metric type, stable since Kubernetes 1.30, targets a single container:

code
metrics:
- type: ContainerResource
  containerResource:
    name: cpu
    container: application
    target:
      type: Utilization
      averageUtilization: 60

## Custom metrics autoscaling

code
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp-custom-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 2
  maxReplicas: 20
  metrics:
  - type: Pods
    pods:
      metric:
        name: http_requests_per_second
      target:
        type: AverageValue
        averageValue: "1000"

This HPA only works if something serves the custom.metrics.k8s.io API, typically a metrics adapter installed in the cluster that exposes values from a system such as Prometheus. Metrics Server does not provide custom metrics. See Prometheus Monitoring for collecting the underlying metric.

## Controlling scaling speed

The behavior field tunes how fast the autoscaler reacts. By default, scale-down uses a 300-second stabilization window, scale-up has none, and the cluster-wide tolerance is 10%.

code
spec:
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 600
      policies:
      - type: Percent
        value: 50
        periodSeconds: 60
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
      - type: Pods
        value: 4
        periodSeconds: 15
      selectPolicy: Max

## HPA commands

code
# Create an HPA for a Deployment (the HPA takes the Deployment's name)
kubectl autoscale deployment myapp --cpu=70% --min=2 --max=10

# View HPA status
kubectl get hpa
kubectl get hpa myapp --watch

# Describe an HPA
kubectl describe hpa myapp

# Delete an HPA
kubectl delete hpa myapp

The older --cpu-percent=70 flag is deprecated. Current kubectl prints a warning and asks for --cpu with a percentage (70%) or a milliCPU quantity.

# Resource management

## Resource requests and limits

Set resources per container in the pod template:

code
containers:
- name: myapp
  image: myapp:1.0.0
  resources:
    requests:
      memory: "256Mi"
      cpu: "250m"
    limits:
      memory: "512Mi"
      cpu: "500m"

## Quality of Service (QoS) classes

Kubernetes assigns each pod a QoS class, which influences eviction order when a node runs short of resources.

Guaranteed: every container in the pod has a memory request and limit, and a CPU request and limit, and each request equals its limit.

code
resources:
  requests:
    memory: "512Mi"
    cpu: "500m"
  limits:
    memory: "512Mi"
    cpu: "500m"

Burstable: the pod does not meet the Guaranteed criteria, but at least one container has a memory or CPU request or limit.

code
resources:
  requests:
    memory: "256Mi"
    cpu: "250m"
  limits:
    memory: "512Mi"
    cpu: "500m"

BestEffort: no container sets any CPU or memory request or limit.

The class is evaluated across all containers in the pod. A pod with one container that meets the Guaranteed criteria and another that sets no resources is Burstable.

## Resizing a running pod

In-place pod resize has been stable since Kubernetes 1.35. It changes a running pod's requests and limits through the resize subresource, without recreating the pod. It requires a kubectl client of 1.32 or later.

code
kubectl patch pod myapp-pod --subresource resize --patch \
  '{"spec":{"containers":[{"name":"myapp", "resources":{"requests":{"cpu":"800m"}, "limits":{"cpu":"800m"}}}]}}'

A container's resizePolicy decides whether a change is applied without a restart (NotRequired, the default) or needs one (RestartContainer), which is often necessary for memory because many runtimes cannot adjust their memory allocation dynamically:

code
resizePolicy:
- resourceName: cpu
  restartPolicy: NotRequired
- resourceName: memory
  restartPolicy: RestartContainer

The pod's QoS class is fixed at creation and cannot change through a resize. A resized Guaranteed pod must keep requests equal to limits.

## Resource quotas

code
apiVersion: v1
kind: ResourceQuota
metadata:
  name: compute-quota
  namespace: production
spec:
  hard:
    requests.cpu: "10"
    requests.memory: 20Gi
    limits.cpu: "20"
    limits.memory: 40Gi
    pods: "50"

When a quota covers CPU or memory, every new pod in that namespace must specify requests or limits for those resources, or the control plane may reject it. A LimitRange can supply defaults.

# Troubleshooting pod restarts

## Common causes

  1. •OOMKilled: the container exceeded its memory limit
  2. •CrashLoopBackOff: the application keeps crashing
  3. •ImagePullBackOff: the image cannot be pulled
  4. •Liveness probe failures: the kubelet restarts containers that fail the probe
  5. •Resource pressure: the node evicts pods when it runs out of resources

## Debugging steps

code
# Check pod status and recent events
kubectl get pods
kubectl describe pod <pod-name>

# View recent events, newest last
kubectl get events --sort-by='.lastTimestamp'

# Check logs, including the previous container instance
kubectl logs <pod-name>
kubectl logs <pod-name> --previous

# Check resource usage (requires Metrics Server)
kubectl top pod <pod-name>
kubectl top nodes

# Run a command in the pod
kubectl exec -it <pod-name> -- /bin/sh

# Attach a debugging container to a pod whose image has no shell
kubectl debug -it <pod-name> --image=busybox:1.37 --target=<container-name>

# Check node capacity and allocated resources
kubectl describe node <node-name>

## Fixing high restart counts

code
# Raise memory for a container that is being OOMKilled
kubectl set resources deployment myapp \
  --limits=memory=1Gi \
  --requests=memory=512Mi

# Give a slow-starting application time to start with a startup probe
kubectl patch deployment myapp -p '
{
  "spec": {
    "template": {
      "spec": {
        "containers": [{
          "name": "myapp",
          "startupProbe": {
            "httpGet": {"path": "/health", "port": 8080},
            "periodSeconds": 5,
            "failureThreshold": 30
          }
        }]
      }
    }
  }
}'

A startup probe holds off liveness and readiness checks until the application is up, so it is a better fix for slow starts than raising initialDelaySeconds on the liveness probe.

# Best practices

  1. •Use Helm for applications with several environments, and run helm lint and helm template in CI.
  2. •Set requests on every container, because HPA utilization and quota admission both depend on them.
  3. •Configure HPA for variable load, and tune behavior to avoid flapping.
  4. •Plan for the Gateway API instead of building new clusters around Ingress, and migrate off the retired Ingress NGINX controller.
  5. •Monitor resource usage with a real monitoring stack rather than Metrics Server alone.
  6. •Use startup and readiness probes to control rollouts and slow starts.
  7. •Use namespaces for isolation, quotas, and Pod Security Admission levels.
  8. •Implement network policies, which require a network plugin that enforces them.
  9. •Keep manifests and Helm values in Git, and apply them through GitOps.

# Next steps

  1. •Create a Helm chart for one of your applications and add it to CI with helm lint.
  2. •Install the Gateway API CRDs and a controller on a test cluster, and route a hostname to a Service.
  3. •Add an HPA to a stateless service and watch it with kubectl get hpa --watch under load.
  4. •Trace a failing pod from describe to logs --previous to kubectl debug.
  5. •Build the container images these workloads run with the patterns in Advanced Docker, and explore service meshes such as Istio and Linkerd.

# Key takeaways

  • →Helm 4 is the current major version, get-helm-4 is the documented installer, and the --atomic and --force flags were renamed --rollback-on-failure and --force-replace.
  • →The Ingress API is frozen and the Kubernetes project recommends the Gateway API, while the community Ingress NGINX controller stopped receiving releases and security fixes after March 2026.
  • →Controller-specific Ingress annotations are not portable, and a rewrite annotation copied between controllers can break path routing silently.
  • →An HPA needs Metrics Server for CPU and memory, needs CPU requests on the target containers, and needs a custom metrics adapter before Pods or External metrics work.
  • →Use kubectl autoscale --cpu=70% because --cpu-percent is deprecated, and tune scale-down speed with the HPA behavior field.
  • →A pod's QoS class is computed across all of its containers, and it stays fixed even though in-place resource resize is stable since Kubernetes 1.35.
  • →A startup probe is the right fix for slow-starting applications, and ResourceQuotas on CPU or memory require every new pod to declare requests or limits.

# Further reading

Test yourself: Advanced Kubernetes assessment

All posts