- An Azure subscription. If you don't have one, you can create a free account.
- Visual Studio Code.
- Azure CLI version 2.0.43 or higher.
- Helm
-
Create an AKS cluster with Azure Dev Spaces by running the following script, specifying the AKS name and region:
source ./create-aks.sh bikesharing01 eastus2
This sets up an AKS cluster named
bikesharing01
in resource groupbikesharing01
in theeastus2
region. -
Run the app's API and Data services.
source ./build-run-app.sh
Tip: Ensure you run this command from the source repository's root folder.
-
Open the web frontend in a browser (the previous script displays the webapp's url, or run
azds list-uris
). Sign into the web app using one of the sample customer accounts, as defined in the file PopulateDatabase/data.json.
If you want to demo finding and fixing a bug: bikes are still (incorrectly) displayed as available even if the bike is currently in use.
- Open the webapp in the browser, and sign in with one of the sample user accounts (e.g. username=holly).
- Select a bike and rent it. Remember the bike, as we'll refer to it later.
- Navigate to the sign-in page by appending '/signin' to the root URL.
We'll demonstrate how multiple developers on a team can use the same cluster, so let's create multiple child dev spaces:
azds space select -n dev/stephen
azds space select -n dev/lisa
azds space select -n dev/john
-
Our team is building a Bike Sharing app where you can view available bikes in your area, rent a bike, and then later return it to a designated location. You're billed for the time you used the bike when you return it.
- Sign into the web app as a different user, for example username=Percy
- Select a bike, then click "Rent".
- Click through the experience for returning a bike: click "Return bike", then "Confirm return". Optionally submit a review.
-
Most of the time this process works, but we currently seem to have a bug where, sometimes, a bike can't be rented.
- Select the bike that Holly has checked out.
- Click "Rent" - nothing happens: no confirmation, no error.
-
Our app consists of several services -- users, bikes, reservations, billing, reviews, etc -- and I've been asked to track the bug down. I'll start with the
Bikes
service, as maybe I can glean some clues about what's different about this particular problem bike. First, let's connect to the cluster where the full app is running:- Open a terminal window, and run:
az aks use-dev-spaces -g bikesharing01 -n bikesharing01
(Your resource group and cluster name may be different.) - When prompted, select a child dev space, for example:
dev/john
(you can always change selection viaazds space select
).
- Open a terminal window, and run:
-
Now let's debug the
bikes
service:- Open VS Code on the
./Bikes
folder. If prompted by the Dev Spaces extension, click 'Yes' to generate debug configuration. - Set a debug breakpoint in
server.js
insideGET bike
(around line 228).// get bike ------------------------------------------------------------ app.get('/api/bikes/:bikeId', function(req, res) {
- Enzure the AZDS debugger profile is selected: Attach to server (AZDS).
- Hit F5 - this syncs code to AKS, builds the container image, deploys it in a pod, and attaches the debugger to it.
- Open the browser to the page that displays available bikes, and then select the "problem bike". Our debug breakpoint is not hit - that's a good sign that shows how anyone else working in the same cluster will be unaffected by our activity in our own dev space.
- To reach our specific instance of the
Bikes
service, prefix the web app's URL with<dev-space-name>.s.
For example:http://john.s.dev.bikesharingweb...aksapp.io
. This will route requests tohttp://bikes
to our version of thebikes
service running in thejohn
namespace.- Prefix the URL appropriately in the browser and refresh the page - the debug breakpoint in VS Code will activate.
- Step through the code - even though the container we're debugging is running in AKS, you'll notice that the debugger is reasonably responsive. And, we have access to the full richness of data in the debugger: local variables, call stacks, streaming logs, etc.
- Stepping through the code we notice that a Mongo database request is made to retrieve bike details. We can inspect the local variable
theBike
to glean detailed bike info.- Set another breakpoint on the last line of code (because it's part of a separate callback function):
res.send(theBike);
- Continue execution to hit this last breakpoint.
- Inspecting
theBike
in the debugger, we notice something doesn't seem right:theBike.available = false
.
- Set another breakpoint on the last line of code (because it's part of a separate callback function):
- Open VS Code on the
-
It may be that this bike shouldn't have been displayed as an available bike in the app's preceeding page.
- Navigate to the function that handles
GET availableBikes
(around line 99):// find bike ------------------------------------------------------------ app.get('/api/availableBikes', function (req, res) {
- Set a breakpoint on the last line of code for that function:
res.send(data);
- In the web app, navigate to view the list of available bikes (click on the app's logo in the header).
- In the debugger, view the
data
variable. We notice that aside from our "problem bike", the other bikes areavailabe = true
.
- Navigate to the function that handles
-
Let's experiment with a fix.
- Uncomment line 104 that modifies the
query
filter object that is passed to mongo.// BUG! Uncomment code to fix :) query = { available: true };
- Save the code file.
- Refresh the page in the browser. Our problem bike is filtered out! Notice how seeing the updated behavior is fast - the container image didn't need to be recreated; instead, the updated code was synced directly to the running container and
nodemon
was restarted (for compiled languages like C# or Java then a re-compilation is kicked off inside the container instance). - Notice that if we remove the
john.s.
prefix in the browser's URL, then we see the original behavior (our modifiedbikes
service indev/john
is not hit).
- Uncomment line 104 that modifies the
Our next step would be to continue testing our fix, then commit and push to the source repo. If we have a CI/CD pipeline set up, it will be triggered to update the team's baseline (the 'dev' namespace). At that point, everyone working in our AKS cluster will automatically see the updated behavior (this is another benefit of working in a shared team cluster, because the team always work with up to date dependencies).
Delete the AKS cluster's resource group to permanently delete all Azure resources created in this walkthrough.
# View AKS clusters
az aks list -o table
# Delete all resources in group `bikesharing01`
az group delete -n bikesharing01 --no-wait