There is a simple C# rest API dotnet app, called GuineaPig
that performs some CPU intensive computations, in order to simulate load in your cluster.
The source code is located under src
folder. If you use Visual Studio open app.sln
file.
- build and push application image to Azure Container Registry
- deploy
GuineaPig
application into the cluster
The simplest way to build and push image is to use az acr build
command. Let's publish GuineaPig
image to the Azure Container Registry.
Note! Don't forget to replace
iacws5<YOU-UNIQUE-ID>acr
with your ACR instance name.
# Go to aks-workshops\05-scaling-options-in-aks\src\GuineaPig folder
cd src\GuineaPig
# Build and publish guinea-pig:v1 image into your ACR
az acr build --registry iacws5<YOU-UNIQUE-ID>acr --image guinea-pig:v1 --file Dockerfile ..
Create new deployment.yaml
file with the following content. Replace image
with your ACR instance name.
apiVersion: apps/v1
kind: Deployment
metadata:
name: guinea-pig
labels:
app: guinea-pig
spec:
replicas: 1
selector:
matchLabels:
app: guinea-pig
template:
metadata:
labels:
app: guinea-pig
spec:
containers:
- name: api
image: iacws5<YOU-UNIQUE-ID>acr.azurecr.io/guinea-pig:v1
imagePullPolicy: IfNotPresent
resources:
requests:
cpu: 200m
limits:
cpu: 400m
livenessProbe:
httpGet:
path: /health
port: 80
initialDelaySeconds: 3
periodSeconds: 3
---
apiVersion: v1
kind: Service
metadata:
name: guinea-pig-service
labels:
app: guinea-pig
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: guinea-pig
type: ClusterIP
Deploy application into default
namespace.
# Deploy application into default namespace
kubectl apply -f deployment.yaml
deployment.apps/guinea-pig created
service/guinea-pig-service created
# Check that pod is up and running
kubectl get po
NAME READY STATUS RESTARTS AGE
guinea-pig-6c994669b7-c8rtz 1/1 Running 0 32s
# Check that service was created
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
guinea-pig-service ClusterIP 10.0.49.164 <none> 80/TCP 47s
Now let's test if application is actually up and running. We will use our old freind - busyboxplus:curl image, mainly because it contains curl
command that we need for our testing.
# Run pod as interactive shell
kubectl run curl -i --tty --rm --restart=Never --image=radial/busyboxplus:curl -- sh
# Here is prompt from withing the pod
[ root@curl:/ ]$
# Call api endpoint. It should response with "[guinea-pig] - OK."
[ root@curl:/ ]$ curl http://guinea-pig-service/api
[guinea-pig] - OK.
In the separate terminal window, watch application logs.
# Get pod name
kubectl get po
NAME READY STATUS RESTARTS AGE
guinea-pig-75f86bcf55-bzb5g 1/1 Running 0 2m18s
# Get guinea-pig application logs
kubectl logs guinea-pig-75f86bcf55-bzb5g -f
[21:26:36 WRN] Failed to determine the https port for redirect.
[21:26:56 INF] [guinea-pig] - OK.
Now let's test another application endpoint from the busybox
shell.
[ root@curl:/ ]$ curl http://guinea-pig-service/api/highcpu
[ root@curl:/ ]$ curl http://guinea-pig-service/api/highcpu
You should see new logs appear from kubectl logs
window
kubectl logs guinea-pig-75f86bcf55-bzb5g -f
[21:26:36 WRN] Failed to determine the https port for redirect.
[21:26:56 INF] [guinea-pig] - OK.
[21:26:58 INF] [guinea-pig] - OK.
[21:32:05 INF] [guinea-pig.highcpu] - execution took 18 ms.
[21:32:05 INF] [guinea-pig.highcpu] - execution took 18 ms.
- Visual Studio 2019 Community Edition
- Download .NET 5.0
- Create your first Docker container with an ASP.NET web app
- Visual Studio Container Tools with ASP.NET Core
- Container Tools in Visual Studio
- How to configure Visual Studio Container Tools
- az acr build command
- Push your first image to a private Docker container registry using the Docker CLI