Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove env tip #20

Merged
merged 7 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 6 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,15 @@
# AKS-LABS

Grab and go resources to learn about Azure Kubernetes Service (AKS)
Grab and go resources to learn about Kubernetes and Azure Kubernetes Service (AKS)

## Features

This project framework provides the following features:

* Feature 1
* Feature 2
* ...
The labs are organized by topic and are designed to be hands-on, with step-by-step instructions.

## Getting Started

### Prerequisites

(ideally very short, if any)

- OS
- Library version
- ...

### Installation

(ideally very short)

- npm install [package name]
- mvn install
- ...

### Quickstart
(Add steps to get up and running quickly)

1. git clone [repository clone url]
2. cd [repository name]
3. ...


## Demo

A demo app is included to show how to use the project.

To run the demo, follow these steps:

(Add steps to start up the demo)

1.
2.
3.
There are a couple of ways to get started with the labs.

## Resources
1. You can run the [Setting Up the Lab Environment](https://azure-samples.github.io/aks-labs/docs/getting-started/setting-up-lab-environment)

(Any additional resources or related projects)
2. You can run the [Kubernetes the Easy Way with AKS Automatic](https://azure-samples.github.io/aks-labs/docs/getting-started/aks-automatic)

- Link to supporting information
- Link to similar sample
- ...
In either case, you will wind up a AKS cluster running in Azure on which you can run any of the labs.
13 changes: 7 additions & 6 deletions docs/getting-started/aks-automatic.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Once the resources are deployed, you can proceed with the workshop.

Let's jump right in and deploy an application to an AKS Automatic cluster. In this section, you will use AKS Automated Deployment to deploy a sample application hosted on GitHub to your AKS cluster.

With AKS, the [Automated Deployments](https://learn.microsoft.com/azure/aks/automated-deployments) feature allows you to create [GitHub Actions workflows](https://docs.github.com/actions) that allows you to start deploying your applications to your AKS cluster with minimal effort. All you need to do is point it at a GitHub repository with your application code.
With AKS, the [Automated Deployments](https://learn.microsoft.com/azure/aks/automated-deployments) feature allows you to create [GitHub Actions workflows](https://docs.github.com/actions) that allows you to start deploying your applications to your AKS cluster with minimal effort. All you need to do is point it at a GitHub repository with your application code.

If you have Dockerfiles or Kubernetes manifests in your repository, that's great, you can simply point to them in the Automated Deployments setup. If you don't have Dockerfiles or Kubernetes manifests in your repository, don't sweat... Automated Deployments can create them for you!

Expand Down Expand Up @@ -287,11 +287,11 @@ kubectl patch nodepool default --type='merge' -p '{

### Review the pull request

Back in the Azure portal, click on the **Approve pull request** button to view the pull request to be taken to the pull request page in your GitHub repository.
Once the deployment is complete, click on the **Approve pull request** button to view the pull request to be taken to the pull request page in your GitHub repository.

![Automated Deployment success](./assets/aks-automatic/deploy-app-done.png)

In the pull request review, click on the **Files changed** tab to view the changes that were made by the Automated Deployments workflow.
In the pull request review, click on the **Files changed** tab to view the changes that were made by the Automated Deployments workflow.

![GitHub pull request files changed](./assets/aks-automatic/github-pull-request-files.png)

Expand Down Expand Up @@ -342,15 +342,15 @@ If the deploy step fails, it is likely that Node Autoprovisioning (NAP) is still

### Test the deployed application

Back in the Azure portal, click the **Close** button to close the Automated Deployments setup.
Back in the Azure portal, click the **Close** button to close the Automated Deployments setup.

In the left-hand menu, click on **Services and ingresses** under the **Kubernetes resources** section. You should see a new service called `contoso-air` with a public IP address assigned to it. Click on the IP address to view the deployed application.

![Contoso Air service](./assets/aks-automatic/contoso-air-service-ip.png)

With AKS Automated Deployments, every time you push application code changes to your GitHub repository, the GitHub Action workflow will automatically build and deploy your application to your AKS cluster. This is a great way to automate the deployment process and ensure that your applications are always up-to-date!

Let's test the application functionality by clicking the **Login** link in the upper right corner of the page.
Let's test the application functionality by clicking the **Login** link in the upper right corner of the page.

![Contoso Air application](./assets/aks-automatic/contoso-air.png)

Expand Down Expand Up @@ -450,7 +450,7 @@ You will see the YAML manifest for the contoso-air application with the highligh

![AKS service connector yaml snippet for contoso-air](./assets/aks-automatic/service-connector-yaml-deploy.png)

Scroll through the YAML manifest to view the changes highlighted in yellow, then click **Apply** to apply the changes to the application. This will redeploy the contoso-air application with the new connection details.
Scroll through the YAML manifest to view the changes highlighted in yellow, then click **Apply** to apply the changes to the application. This will redeploy the contoso-air application with the new connection details.

![AKS service connector yaml snippet apply](./assets/aks-automatic/service-connector-yaml-apply.png)

Expand Down Expand Up @@ -617,6 +617,7 @@ The workbook visuals will include a query button that you can click to view the

If you click on the **Logs** section in the left-hand menu, you can view the logs collected by Container Insights. Here, you can write your own KQL queries or run pre-configured queries to logs from your cluster and applications. The Logs section should be configured to open **Queries hub** which displays a list of pre-configured queries that you can run. Click on a query and click **Run** to view the results.


### Visualizing metrics with Grafana

The Azure Portal provides a great way to view metrics and logs, but if you prefer to visualize the data using Grafana, or execute complex queries using PromQL, you can use the Azure Managed Grafana instance that was created with the AKS Automatic cluster.
Expand Down
61 changes: 31 additions & 30 deletions docs/getting-started/setting-up-lab-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,23 @@ Verify the contents of the **main.bicep** file by running the following command.
cat main.bicep
```

Run the following command to save your user object ID to a variable, save it to the **.env** file, and reload the environment variables.
Run the following command to save your user object ID to a variable.

```bash
export USER_ID="$(az ad signed-in-user show --query id -o tsv)"
```

Run the following command to save the deployment name to a variable. In this example we set the deployment name to **labdemo**.

```bash
export DEPLOY_NAME="labdemo"
```

Run the following command to deploy Bicep template into the resource group.

```bash
az deployment group create \
--name ${DEPLOY_NAME} \
--resource-group $RG_NAME \
--template-file main.bicep \
--parameters userObjectId=${USER_ID} \
Expand Down Expand Up @@ -149,15 +156,6 @@ Before you create the AKS cluster, run the following command to install the aks-
az extension add --name aks-preview
```

Run the following command to set a name for the AKS cluster, save it to the **.env** file, and reload the environment variables.

```bash
cat <<EOF >> .env
AKS_NAME="myAKSCluster"
EOF
source .env
```

:::info[Important]

Before creating the AKS cluster you need to decide on the Kubernetes version to use. It is recommended to use the latest version of Kubernetes available in the region you are deploying to. You can find the latest version of Kubernetes available in your region by running the following command:
Expand Down Expand Up @@ -260,27 +258,30 @@ Monitoring and logging are essential for maintaining the health and performance

The Bicep template that was deployed earlier should be completed by now. All you need to do next is enable [metrics monitoring](https://learn.microsoft.com/azure/azure-monitor/containers/kubernetes-monitoring-enable?tabs=cli) and on the cluster by linking the monitoring resources to the AKS cluster.

Run the following commands to get the resource IDs for the resources that were created, save them to the **.env** file, and reload the environment variables.
:::tip

The Bicep template has outputs defined so you can access the names and resource IDs of the monitoring resources. However, the outputs are stored as key-value pairs. You can use this scriplet to export the outputs as environment variables.

```bash
cat <<EOF >> .env
MONITOR_ID="$(az monitor account list -g ${RG_NAME} --query "[0].id" -o tsv)"
GRAFANA_NAME="$(az grafana list -g ${RG_NAME} --query "[0].name" -o tsv)"
GRAFANA_ID="$(az grafana list -g ${RG_NAME} --query "[0].id" -o tsv)"
LOGS_ID="$(az monitor log-analytics workspace list -g ${RG_NAME} --query "[0].id" -o tsv)"
AKV_NAME="$(az keyvault list --resource-group ${RG_NAME} --query "[0].name" -o tsv)"
AKV_ID="$(az keyvault list --resource-group ${RG_NAME} --query "[0].id" -o tsv)"
AKV_URL="$(az keyvault list --resource-group ${RG_NAME} --query "[0].properties.vaultUri" -o tsv)"
ACR_NAME="$(az acr list --resource-group ${RG_NAME} --query "[0].name" -o tsv)"
ACR_ID="$(az acr list --resource-group ${RG_NAME} --query "[0].id" -o tsv)"
ACR_SERVER="$(az acr list --resource-group ${RG_NAME} --query "[0].loginServer" -o tsv)"
EOF
source .env
while IFS= read -r line; \
do echo "exporting $line"; \
export $line=$(az deployment group show -g ${RG_NAME} -n ${DEPLOY_NAME} --query "properties.outputs.${line}.value" -o tsv); \
done < <(az deployment group show -g $RG_NAME -n ${DEPLOY_NAME} --query "keys(properties.outputs)" -o tsv)
```

:::tip

> Whenever you want to see the contents of the **.env** file, run the **cat .env** command.
The output shows the names environment variables being exported so you can use them later and looks like this:

```text
exporting monitor_id
exporting grafana_id
exporting grafana_Name
exporting logs_id
exporting akv_id
exporting akv_name
exporting akv_url
exporting acr_id
exporting acr_server
```

:::

Expand All @@ -291,8 +292,8 @@ az aks update \
--resource-group ${RG_NAME} \
--name ${AKS_NAME} \
--enable-azure-monitor-metrics \
--azure-monitor-workspace-resource-id ${MONITOR_ID} \
--grafana-resource-id ${GRAFANA_ID} \
--azure-monitor-workspace-resource-id ${monitor_id} \
--grafana-resource-id ${grafana_id} \
--no-wait
```

Expand All @@ -303,7 +304,7 @@ az aks enable-addons \
--resource-group ${RG_NAME} \
--name ${AKS_NAME} \
--addon monitoring \
--workspace-resource-id ${LOGS_ID} \
--workspace-resource-id ${logs_id} \
--no-wait
```

Expand Down
48 changes: 9 additions & 39 deletions docs/storage/assets/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,6 @@ resource keyVaultAdministratorRoleAssignment 'Microsoft.Authorization/roleAssign
}
}

// resource keyVaultCertificatesOfficerRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
// name: guid(subscription().id, resourceGroup().id, userObjectId, 'Key Vault Certificates Officer')
// scope: azureKeyVault
// properties: {
// principalId: userObjectId
// principalType: 'User'
// roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', '00482a5a-887f-4fb3-b363-3b7fe8e74483')
// }
// }

// resource keyVaultCryptoUserRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
// name: guid(subscription().id, resourceGroup().id, userObjectId, 'Key Vault Crypto User')
// scope: azureKeyVault
// properties: {
// principalId: userObjectId
// principalType: 'User'
// roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', '00482a5a-887f-4fb3-b363-3b7fe8e74483')
// }
// }

resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-11-01-preview' = {
name: 'myregistry${uniqueString(subscription().id, resourceGroup().id, deployment().name)}'
location: location
Expand All @@ -132,22 +112,12 @@ resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-11-01-pr
}
}

// resource acrPullRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
// name: guid(subscription().id, resourceGroup().id, userObjectId, 'AcrPull')
// scope: containerRegistry
// properties: {
// principalId: userObjectId
// principalType: 'User'
// roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d')
// }
// }

// resource acrPushRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
// name: guid(subscription().id, resourceGroup().id, userObjectId, 'AcrPush')
// scope: containerRegistry
// properties: {
// principalId: userObjectId
// principalType: 'User'
// roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', '8311e382-0749-4cb8-b61a-304f252e45ec')
// }
// }
output monitor_id string = metricsWorkspace.id
output grafana_id string = grafanaDashboard.id
output grafana_Name string = grafanaDashboard.name
output logs_id string = logWorkspace.id
output akv_id string = azureKeyVault.id
output akv_name string = azureKeyVault.name
output akv_url string = azureKeyVault.properties.vaultUri
output acr_id string = containerRegistry.id
output acr_server string = containerRegistry.properties.loginServer
Loading