Skip to content

Playground

This guide will help you set up a local Kubernetes cluster to test the elasti operator and resolver. Follow these steps from the project home directory.

1. Local Cluster

If you don't already have a local Kubernetes cluster, you can set one up using Minikube, Kind or Docker-Desktop:

kind create cluster --config ./playground/infra/kind-config.yaml
minikube start

Enable it in Docker-Desktop

2. Start a Local Docker Registry

Run a local Docker registry container, to push our images locally and access them in our cluster.

docker run -d --restart=always -p 5001:5000 --name kind-registry registry:2;

# If you are using kind, connect the registry to kind network
docker network create kind
docker network connect "kind" kind-registry

Add registry to Minikube and Kind

You will need to add this registry to Minikube and Kind. With Docker-Desktop, it is automatically picked up.

In MacOS, 5000 is not available, so we use 5001 instead.

3. Build & Publish Resolver & Operator

Once you have made the necessary changes to the resolver or operator, you can build and publish it using the following commands:

make -C resolver docker-build docker-push IMG=localhost:5001/elasti-resolver:v1alpha1
make -C operator docker-build docker-push IMG=localhost:5001/elasti-operator:v1alpha1

Make sure you have configured the local context in kubectl. With kind, it is automatically picked up,

4. Setup Prometheus

We will setup a sample prometheus to read metrics from the ingress controller.

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
  --namespace monitoring \
  --create-namespace \
  --set alertmanager.enabled=false \
  --set grafana.enabled=false \
  --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false

5. Install ingress or gateway

Install one edge from Gateway and ingress integrations:

6. Deploy KubeElasti Locally

We will be using playground/infra/elasti-demo-values.yaml for the helm installation. Configure the image uri according to the requirement. Post that follow below steps from the project home directory:

kubectl create namespace elasti
helm upgrade --install elasti ./charts/elasti -n elasti -f ./playground/infra/elasti-demo-values.yaml

If you want to enable monitoring, please make enableMonitoring true in the values file.

7. Deploy a demo service

Run a demo application in your cluster. We will use a sample httpbin service to demonstrate how to configure a service to handle its traffic via elasti.

kubectl create namespace target
kubectl apply -f ./playground/config/demo-deployment-target.yaml -n target

Expose the demo through your edge (for example Istio VirtualService or Envoy HTTPRoute). See Istio or Envoy Gateway.

This will deploy a target-deployment (httpbin) Service, Deployment, and Ingress in the target namespace.

8. Create ElastiService Resource

Using the ElastiService Definition, create a manifest file for your service and apply it. For demo, we use the below manifest.

kubectl -n target apply -f ./playground/config/demo-deployment-elastiService.yaml

9. Test the service

9.1 Scale down the service

kubectl -n target scale deployment target-deployment --replicas=0

9.2 Send request to the service while target is scaled down

kubectl run -it --rm curl --image=alpine/curl -- http://target-deployment.target.svc.cluster.local/headers

9.3 Port-forward ingress or gateway

Use the port-forward command for your integration (NGINX, Istio, or Envoy Gateway).

You should see the target service pod getting scaled up and response from the new pod.

10. Debug tips

10.1 Watch logs

kubectl logs -n elasti deployments/elasti-operator-controller-manager -f
kubectl logs -n elasti deployments/elasti-resolver -f
kubectl logs -n target deployments/target-deployment -f
kubectl logs -n istio-system deployments/istiod -f

10. Delete KubeElasti

helm delete elasti -n elasti

11. Redeploy KubeElasti

In case you want to redeploy KubeElasti, with your latest changes, you can use the below command:

11.1 Delete the ElastiService

kubectl -n target delete -f ./playground/config/demo-deployment-elastiService.yaml

11.2 Delete the KubeElasti

helm delete elasti -n elasti

11.3 Remove old images

docker rmi localhost:5001/elasti-resolver:v1alpha1

docker rmi localhost:5001/elasti-operator:v1alpha1

Post this, repeat steps 6 and 8, to redeploy KubeElasti.