Skip to content

Commit

Permalink
kubernetes-resume-challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
TomiwaAribisala-git committed Mar 22, 2024
1 parent 14cadad commit a508941
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 26 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,4 @@ jobs:
kubectl apply -f ecom-web-configmap.yml
kubectl apply -f ecom-web-config.yml
kubectl apply -f ecom-web.yml
kubectl apply -f ecom-web-svc.yml
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
kubectl apply -f php-apache-svc.yml
kubectl apply -f php-apache.yml
kubectl apply -f ecom-web-svc.yml
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,47 @@ docker run -d —network some-network —name ecom-web -p 8080:80 ecom-web:v1

![Wesbite-Rollback-Update](./images/website-rollback.png)


## Implement Liveness and Readiness Probes

## Implement Persistent Storage
- Defined [PersistentVolumeClaim](./kubernetes/mariadb-pvc.yml), [PersistentVolume](./kubernetes/mariadb-pv.yml) and [StorageClass](./kubernetes/storage-class.yml) for MariaDB Storage needs

## Autoscaling the application based on CPU usage to handle unpredictable traffic spikes
- Installed Kubernetes Metrics Server: `kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml`
- Created a [HorizontalPodAutoscaler Deployment](./kubernetes/php-apache.yml) and [HorizontalPodAutoscaler Service](./kubernetes/php-apache-svc.yml)

![Kubernetes-Metrics-Server](./images/metrics-server.png)

- Created a [HorizontalPodAutoscaler Deployment/Service](./kubernetes/ecom.yml)

![Ecom-Server](./images/ecom.png)

- Apply HPA: `kubectl autoscale deployment ecom-web --cpu-percent=50 --min=2 --max=10`

![HPA](./images/ecom-web-autoscale.png)

- Observe HPA: `kubectl get hpa`

![Observe-HPA](./images/observe-hpa.png)

- See how Autoscaler reacts by increasing load; Using Load-Generator:`kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"`, Using Apache Bench: `alias ab='kubectl run test-load --rm --tty -i --restart='Never' --image devth/alpine-bench --command -- /go/bin/main'`,
`ab -n 10000 -c 900 -s 300 https://my.site123.com/(replace URL with your ecom-web service)`

![Increase Load](./images/increase-load.png)

- Monitor Autoscaling: `kubectl get hpa ecom-web --watch`, high CPU load and more replicas

![Monitor HPA](./images/monitor-hpa.png)

- Monitor Deployment: `kubectl get deployment ecom-web`

![Monitor Deployment](./images/monitor-deployment.png)

- Stop generating load: Terminate the `busybox` load generation by typing `<Ctrl> + C`
- Verify the result state: `kubectl get hpa ecom-web --watch`

![Result State](./images/result-state.png)


## Extras
- [HorizontalPodAutoscaler Walkthrough](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/)
Expand Down
Binary file added images/ecom-web-autoscale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/ecom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/metrics-server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/observe-hpa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 1 addition & 5 deletions kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,5 @@ kubectl apply -f ecom-web-svc.yml
```

```sh
kubectl apply -f php-apache-svc.yml
```

```sh
kubectl apply -f php-apache.yml
kubectl apply -f ecom.yml
```
22 changes: 17 additions & 5 deletions kubernetes/php-apache-svc.yml → kubernetes/ecom.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-apache
name: ecom-hpa
spec:
selector:
matchLabels:
run: php-apache
run: ecom-hpa
template:
metadata:
labels:
run: php-apache
run: ecom-hpa
spec:
containers:
- name: php-apache
- name: ecom-hpa
image: registry.k8s.io/hpa-example
ports:
- containerPort: 80
resources:
limits:
cpu: 500m
requests:
cpu: 200m
cpu: 200m
---
apiVersion: v1
kind: Service
metadata:
name: ecom-svc
labels:
run: ecom-svc
spec:
ports:
- port: 80
selector:
run: ecom-hpa
11 changes: 0 additions & 11 deletions kubernetes/php-apache.yml

This file was deleted.

0 comments on commit a508941

Please sign in to comment.