Scale to 0 with EKS — KNative

brew install eksctl
brew install kubectl
brew install kn
# cat ekscluster.yml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: knative
region: eu-north-1
version: "1.22"
nodeGroups:
- name: ng-1
instanceType: m5.large
desiredCapacity: 10
volumeSize: 80
ssh:
allow: true # will use ~/.ssh/id_rsa.pub as the default ssh key
- name: ng-2
instanceType: m5.large
desiredCapacity: 2
volumeSize: 100
ssh:
publicKeyPath: ~/.ssh/id_rsa.pub
eksctl create cluster -f ekscluster.yml
eksctl upgrade cluster -f ekscluster.yml
eksctl upgrade cluster -f ekscluster.yml --approve
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.5.0/serving-crds.yaml
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.5.0/serving-core.yaml
kubectl apply -l knative.dev/crd-install=true -f https://github.com/knative/net-istio/releases/download/knative-v1.5.0/istio.yaml
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.5.0/istio.yaml
kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.5.0/net-istio.yaml
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.5.0/serving-hpa.yaml
# hello.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: hello
spec:
template:
spec:
containers:
- image: gcr.io/knative-samples/helloworld-go
ports:
- containerPort: 8080
env:
- name: TARGET
value: "World"
kubectl apply -f hello.yaml
#Nothing running now:kubectl get deploymentNAME                     READY   UP-TO-DATE   AVAILABLE   AGE
hello-00001-deployment 0/0 0 0 6h7m
#Get Ingress gateway & knative urls
GATEWAY=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
URL=$(kubectl get ksvc -o jsonpath='{.status.url}')
# Call URL to get response
curl http://$GATEWAY/ -H 'Host: $URL'
Hello World!
kubectl get deploymentNAME READY UP-TO-DATE AVAILABLE AGE
hello-00001-deployment 1/1 1 1 6h8m
kubectl delete -f https://github.com/knative/serving/releases/download/knative-v1.5.0/serving-hpa.yaml
kubectl delete -f https://github.com/knative/net-istio/releases/download/knative-v1.5.0/net-istio.yaml
kubectl delete -f https://github.com/knative/net-istio/releases/download/knative-v1.5.0/istio.yaml
eksctl delete cluster -f ekscluster.yml
data:
kubernetes.podspec-securitycontext: "allowed"
kubernetes.podspec-init-containers: "enabled"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store