Quickstart: Develop on Azure Kubernetes Service (AKS) with Helm
Artikkeli
Helm is an open-source packaging tool that helps you install and manage the lifecycle of Kubernetes applications. Similar to Linux package managers like APT and Yum, Helm manages Kubernetes charts, which are packages of pre-configured Kubernetes resources.
In this quickstart, you use Helm to package and run an application on AKS. For information on installing an existing application using Helm, see Install existing applications with Helm in AKS.
Prerequisites
An Azure subscription. If you don't have an Azure subscription, you can create a free account.
You need to store your container images in an Azure Container Registry (ACR) to run your application in your AKS cluster using Helm. Your registry name must be unique within Azure and contain 5-50 alphanumeric characters. Only lowercase characters are allowed. The Basic SKU is a cost-optimized entry point for development purposes that provides a balance of storage and throughput.
Create an Azure resource group using the az group create command. The following example creates a resource group named myResourceGroup in the eastus location.
Azure CLI
az group create --name myResourceGroup --location eastus
Create an Azure Container Registry with a unique name by calling the az acr create command. The following example creates an ACR named myhelmacr with the Basic SKU.
Azure CLI
az acr create --resource-group myResourceGroup --name myhelmacr --sku Basic
Your output should look similar to the following condensed example output. Take note of your loginServer value for your ACR to use in a later step.
Create an Azure resource group using the [New-AzResourceGroup][new-azresourcegroup] cmdlet. The following example creates a resource group named myResourceGroup in the eastus location.
Create an Azure Container Registry with a unique name by calling the New-AzContainerRegistry cmdlet. The following example creates an ACR named myhelmacr with the Basic SKU.
Create an AKS cluster using the az aks create command with the --attach-acr parameter to grant the cluster access to your ACR. The following example creates an AKS cluster named myAKSCluster and grants it access to the myhelmacr ACR. Make sure you replace myhelmacr with the name of your ACR.
Azure CLI
az aks create --resource-group myResourceGroup --name myAKSCluster --location eastus --attach-acr myhelmacr --generate-ssh-keys
Create an AKS cluster using the New-AzAksCluster cmdlet with the -AcrNameToAttach parameter to grant the cluster access to your ACR. The following example creates an AKS cluster named myAKSCluster and grants it access to the myhelmacr ACR. Make sure you replace myhelmacr with the name of your ACR.
To connect a Kubernetes cluster locally, you use the Kubernetes command-line client, kubectl. kubectl is already installed if you use Azure Cloud Shell.
Configure kubectl to connect to your Kubernetes cluster using the az aks get-credentials command. The following command gets credentials for the AKS cluster named myAKSCluster in myResourceGroup.
Azure CLI
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
Configure kubectl to connect to your Kubernetes cluster using the Import-AzAksCredential cmdlet. The following command gets credentials for the AKS cluster named myAKSCluster in myResourceGroup:
Navigate to the azure-vote directory using the cd command.
Bash
cd azure-voting-app-redis/azure-vote/
Build and push the sample application to ACR
Build and push the image to your ACR using the az acr build command. The following example builds an image named azure-vote-front:v1 and pushes it to the myhelmacr ACR. Make sure you replace myhelmacr with the name of your ACR.
Azure CLI
az acr build --image azure-vote-front:v1 --registry myhelmacr --file Dockerfile .
Generate your Helm chart using the helm create command.
Bash
helm create azure-vote-front
Update azure-vote-front/Chart.yaml to add a dependency for the redis chart from the https://charts.bitnami.com/bitnami chart repository and update appVersion to v1, as shown in the following example:
Huomautus
The container image versions shown in this guide have been tested to work with this example but may not be the latest version available.
YAML
apiVersion:v2name:azure-vote-frontdescription:AHelmchartforKubernetesdependencies: - name:redis version:17.3.17 repository:https://charts.bitnami.com/bitnami...# This is the version number of the application being deployed. This version number should be# incremented each time you make changes to the application.appVersion:v1
Update your Helm chart dependencies using the helm dependency update command.
Bash
helm dependency update azure-vote-front
Update azure-vote-front/values.yaml with the following changes.
Add a redis section to set the image details, container port, and deployment name.
Add a backendName for connecting the frontend portion to the redis deployment.
Change image.repository to <loginServer>/azure-vote-front.
Install your application using your Helm chart using the helm install command.
Bash
helm install azure-vote-front azure-vote-front/
It takes a few minutes for the service to return a public IP address. Monitor progress using the kubectl get service command with the --watch argument.
Bash
kubectl get service azure-vote-front --watch
When the service is ready, the EXTERNAL-IP value changes from <pending> to an IP address. Press CTRL+C to stop the kubectl watch process.
Tuloste
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
azure-vote-front LoadBalancer 10.0.18.228 <pending> 80:32021/TCP 6s
...
azure-vote-front LoadBalancer 10.0.18.228 52.188.140.81 80:32021/TCP 2m6s
Navigate to your application's load balancer in a browser using the <EXTERNAL-IP> to see the sample application.
Remove your resource group, AKS cluster, Azure container registry, container images stored in the ACR, and all related resources using the az group delete command with the --yes parameter to confirm deletion and the --no-wait parameter to return to the command prompt without waiting for the operation to complete.
Azure CLI
az group delete --name myResourceGroup --yes--no-wait
Remove your resource group, AKS cluster, Azure container registry, container images stored in the ACR, and all related resources using the Remove-AzResourceGroup cmdlet with the --yes parameter to confirm deletion and the --no-wait parameter to return to the command prompt without waiting for the operation to complete.
Azure PowerShell
Remove-AzResourceGroup -Name myResourceGroup
Huomautus
If you created your AKS cluster with a system-assigned managed identity (the default identity option in this quickstart), the identity is managed by the platform and doesn't require removal.
If you created your AKS cluster with a service principal, the service principal isn't removed when you delete the cluster. To remove the service principal, see AKS service principal considerations and deletion.
Liity tapaamissarjaan ja luo skaalattavia tekoälyratkaisuja, jotka perustuvat reaalimaailman käyttötapauksiin muiden kehittäjien ja asiantuntijoiden kanssa.
Le damos la bienvenida a esta experiencia interactiva de validación de aptitudes. Completar este módulo le ayuda a prepararse para la evaluación de Implementación y administración de contenedores con Azure Kubernetes Service.