Skip to content

Commit d799ae1

Browse files
committed
actualizada la demo de KEDA
1 parent 10cf66e commit d799ae1

File tree

6 files changed

+172
-2
lines changed

6 files changed

+172
-2
lines changed

04-cloud/00-aks/01-brigde-to-kubernetes/01-brigde-to-kubernetes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#https://docs.microsoft.com/en-us/visualstudio/containers/bridge-to-kubernetes?view=vs-2019
22
#https://docs.microsoft.com/en-us/visualstudio/containers/overview-bridge-to-kubernetes?view=vs-2019
3-
3+
# https://marketplace.visualstudio.com/items?itemName=mindaro.mindaro
44
#Variables
55
RESOURCE_GROUP="Bridge-To-Kubernetes"
66
AKS_NAME="lemoncode-dev"

04-cloud/00-aks/02-cluster-autoscaler/cluster-autoscaler.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ az aks update \
3838
#Si comprobamos pasados unos minutos verás que los pods han sido alocados en nuevos nodos
3939
kubectl get po -o wide --watch
4040

41+
#Configurar el perfil del autoescalado: https://docs.microsoft.com/es-es/azure/aks/cluster-autoscaler#using-the-autoscaler-profile
42+
4143
#Si eliminamos el grupo de recursos eliminaremos el clúster
4244
az group delete -n ${RESOURCE_GROUP} --yes --no-wait

04-cloud/00-aks/04-keda/03-keda.sh

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,79 @@
1-
# https://www.returngis.net/2020/06/autoescalar-tus-aplicaciones-en-kubernetes-con-keda/
1+
#Para entender KEDA primero necesitas saber cómo autoescalan los pods dentro de un clúster
2+
3+
### Ejemplo de autoescalado sin KEDA
4+
#Autoescalar tus aplicaciones en Kubernetes: https://www.returngis.net/2020/05/autoescalar-tus-aplicaciones-en-kubernetes/
5+
kubectl apply -f 04-cloud/00-aks/04-keda/manifests/autoscale-with-hpa.yml
6+
kubectl autoscale deployment web --cpu-percent=30 --min=1 --max=5
7+
kubectl get hpa --watch
8+
9+
ab -n 50000 -c 200 http://51.104.177.27/
10+
11+
kubectl describe hpa web
12+
13+
#KEDA
14+
# https://www.returngis.net/2020/06/autoescalar-tus-aplicaciones-en-kubernetes-con-keda/
15+
16+
#Variables
17+
RESOURCE_GROUP="KEDA"
18+
AKS_NAME="lemoncode-keda"
19+
20+
#Instalar Helm
21+
brew install helm
22+
23+
#Añadir el repo de KEDA
24+
helm repo add kedacore https://kedacore.github.io/charts
25+
helm repo update
26+
27+
#Creamos el grupo de recursos
28+
az group create -n ${RESOURCE_GROUP} -l ${LOCATION}
29+
30+
#Creamos un cluster
31+
az aks create -g ${RESOURCE_GROUP} -n ${AKS_NAME} \
32+
--node-count 1 --generate-ssh-keys
33+
34+
#Configuramos kubectl para comunicarnos con nuestro nuevo clúster
35+
az aks get-credentials -g ${RESOURCE_GROUP} -n ${AKS_NAME}
36+
37+
#Creamos un namespace llamado keda
38+
kubectl create namespace keda
39+
40+
#Instalamos los componentes dentro del namespace de KEDA
41+
helm install keda kedacore/keda --namespace keda
42+
43+
kubectl get pods -n keda --watch
44+
45+
#Crear un ScaledObject para el deployment
46+
#Vamos a basar el escalado en los mensajes que haya en una cola de mensajes.
47+
#Para ello nos apoyamos en un servicio llamado Azure Storage
48+
49+
#Creamos una cuenta de almacenamiento
50+
STORAGE_NAME="boxoftasks"
51+
az storage account create --name $STORAGE_NAME --resource-group $RESOURCE_GROUP
52+
ACCOUNT_KEY=$(az storage account keys list --resource-group $RESOURCE_GROUP --account-name $STORAGE_NAME --query "[0].value" --output tsv)
53+
54+
#Creamos una cola dentro de la cuenta de almacenamiento
55+
az storage queue create --name "tasks" \
56+
--account-name $STORAGE_NAME \
57+
--account-key $ACCOUNT_KEY
58+
59+
#Recuperamos la cadena de conexión
60+
CONNECTION_STRING=$(az storage account show-connection-string --name $STORAGE_NAME --resource-group $RESOURCE_GROUP -o tsv)
61+
62+
#La guardamos en un secret de Kubernetes
63+
kubectl create secret generic storage-secret --from-literal=connection-string=$CONNECTION_STRING
64+
65+
kubectl apply -f 04-cloud/00-aks/04-keda/manifests/web-deployment.yml
66+
kubectl get pods --watch
67+
68+
#Ahora creamos un objeto del tipo ScaledObject, propios de KEDA
69+
kubectl apply -f 04-cloud/00-aks/04-keda/manifests/scaledObject.yml
70+
kubectl get scaledobject
71+
kubectl get hpa -w
72+
73+
#Para probar esto añadimos un montón de mensajes en la cola de mensajería, para que escale el despliegue
74+
while true; do az storage message put --content "Hello from KEDA" --queue-name "tasks" --account-name $STORAGE_NAME --account-key $ACCOUNT_KEY; done
75+
76+
#Ahora probamos lo mismo pero para que desescale
77+
az storage message clear --queue-name "tasks" --account-name $STORAGE_NAME --account-key $ACCOUNT_KEY
78+
79+
#En esta página puedes ver todos los scaled object disponibles: https://keda.sh/docs/2.0/scalers/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: web
5+
spec:
6+
replicas: 3
7+
selector:
8+
matchLabels:
9+
app: aspnet
10+
template:
11+
metadata:
12+
labels:
13+
app: aspnet
14+
spec:
15+
containers:
16+
- name: web
17+
image: mcr.microsoft.com/dotnet/core/samples:aspnetapp
18+
resources:
19+
requests:
20+
cpu: "100m"
21+
ports:
22+
- containerPort: 80
23+
24+
---
25+
26+
apiVersion: v1
27+
kind: Service
28+
metadata:
29+
name: aspnet-svc
30+
spec:
31+
type: LoadBalancer
32+
selector:
33+
app: aspnet
34+
ports:
35+
- protocol: TCP
36+
port: 80
37+
targetPort: 80
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: keda.sh/v1alpha1
2+
kind: TriggerAuthentication
3+
metadata:
4+
name: trigger-auth-queue
5+
spec:
6+
secretTargetRef:
7+
- parameter: connection
8+
name: storage-secret
9+
key: connection-string
10+
11+
---
12+
13+
apiVersion: keda.sh/v1alpha1
14+
kind: ScaledObject
15+
metadata:
16+
name: queue-scaledobject
17+
labels:
18+
deploymentName: web-deployment
19+
spec:
20+
scaleTargetRef:
21+
name: web-deployment
22+
pollingInterval: 15
23+
minReplicaCount: 0
24+
maxReplicaCount: 10
25+
triggers:
26+
- type: azure-queue
27+
metadata:
28+
queueName: tasks
29+
queueLength: '5' # Optional. Queue length target for HPA. Default: 5 messages
30+
authenticationRef:
31+
name: trigger-auth-queue
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: web-deployment
5+
labels:
6+
app: web
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: web
12+
template:
13+
metadata:
14+
labels:
15+
app: web
16+
spec:
17+
containers:
18+
- name: nginx
19+
image: nginx:latest
20+
ports:
21+
- name: http
22+
containerPort: 80

0 commit comments

Comments
 (0)