Skip to content

Demo setup

Follow these steps after Installation and when your cluster meets the Prerequisites. You will run a minimal httpbin workload behind ingress or a gateway, attach an ElastiService, apply it, and curl through the edge to see scale-from-zero and idle scale-down.

For NGINX, Istio, or Envoy Gateway install and routing details, use the Gateway and ingress integrations guides.

1. Deploy a Target Application

Before creating an ElastiService, you need a target deployment, service, and a route from your ingress or gateway. The example below uses NGINX Ingress; for other edges, deploy the Deployment and Service from this manifest, then apply the route from Istio or Envoy Gateway.

Create a file named target-deployment.yaml:

target-deployment.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: target
---
apiVersion: v1
kind: Service
metadata:
  name: target-deployment
  namespace: target
spec:
  type: ClusterIP
  selector:
    app: target-deployment
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: target-deployment
  namespace: target
spec:
  replicas: 1
  selector:
    matchLabels:
      app: target-deployment
  template:
    metadata:
      labels:
        app: target-deployment
    spec:
      containers:
        - name: target-deployment
          image: kennethreitz/httpbin
          ports:
            - containerPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: httpbin-ingress
  namespace: target
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/service-upstream: "true"
    nginx.ingress.kubernetes.io/upstream-vhost: "target-deployment.target.svc.cluster.local"
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
          - path: /httpbin(/|$)(.*)
            pathType: ImplementationSpecific
            backend:
              service:
                name: target-deployment
                port:
                  number: 80

The upstream-vhost annotation sets the routing header the resolver expects. See NGINX Ingress integration and Request routing.

Apply the manifest:

kubectl apply -f target-deployment.yaml

Verify the target is running:

kubectl get pods -n target


2. Define an ElastiService

You turn scale-to-zero on for a workload by creating an ElastiService object: it points at your Kubernetes Service and scale target, defines Prometheus triggers, and (optionally) links a KEDA ScaledObject so KubeElasti can pause it while the workload is at zero. For a full walkthrough of every field and option, read the Configuration guide.

The manifest below matches the httpbin example from the previous step. Save it as elasti-service.yaml; you will apply it in the next section.

elasti-service.yaml
apiVersion: elasti.truefoundry.com/v1alpha1
kind: ElastiService
metadata:
  name: target-elastiservice
  namespace: target
spec:
  service: target-deployment
  minTargetReplicas: 1
  cooldownPeriod: 5
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: target-deployment
  triggers:
    - type: prometheus
      metadata:
        query: sum(rate(nginx_ingress_controller_requests{namespace="target", ingress="httpbin-ingress"}[1m])) or vector(0)
        serverAddress: http://kube-prometheus-stack-prometheus.monitoring.svc.cluster.local:9090
        threshold: "0.01"
  probeResponse:
    - method: GET
      path:
        type: PathPrefix
        value: /healthz
      response:
        status: 200
        body: '{"ok":true}'

If your ingress, load balancer, or platform sends health checks while the workload is at zero replicas, add probeResponse rules for those paths. Requests that match are served by the resolver and do not scale the deployment up.


3. Apply the KubeElasti service configuration

Apply the configuration to your Kubernetes cluster:

kubectl apply -f elasti-service.yaml -n <service-namespace>

The pod will be scaled down to 0 replicas if there is no traffic.


4. Test the setup

Port-forward your edge Service to localhost (commands per integration):

Start a watch on the target deployment.

kubectl get pods -n <NAMESPACE> -w

Send a request to the service.

curl -v http://localhost:8080/httpbin

You should see the pods being created and scaled up to 1 replica. A response from the target service should be visible for the curl command. The target service should be scaled down to 0 replicas if there is no traffic for cooldownPeriod seconds.