-
Notifications
You must be signed in to change notification settings - Fork 6
CI CD Manual Setup for AKS
chamindac edited this page Feb 28, 2019
·
20 revisions
az group create -n 'cmbaksrg01' -l 'centralus' --subscription "subscription id or name"
az acr create -n 'cmbaksacr01' -g 'cmbaksrg01' -l 'centralus' --sku basic --subscription "subscription id or name"
az aks create -n 'cmbakscluster01' -g 'cmbaksrg01' -l 'centralus' --disable-rbac --subscription "subscription id or name"
- Setup docker for windows community edition with Linux containers.
- Install git for windows Download git for windows
- Install https://code.visualstudio.com/download
- Install .NET Core SDK (Download installer and install)
- Add git ignore generator extension to vscode
- Add C# extension to vscode
- Add docker extension to vscode
- Create a Team Project in Azure DevOps with a Git repo
- In vscode Command Platte execute command
Git: Cloneand provide the clone url of the Azure DevOps Git repo - Once prompted Open Repository in vscode
- In a Terminal window in vs code execute below command to create new ASP.NET Core project.
dotnet new webapp
- To test the newly created web app execute below commands.
dotnet build
dotnet run
- Open a browser and browse http://localhost:5000 . This might show an error. View details and click Go on to the web page and you would be able to see the web app running.
- Press Ctrl+C to stop web app.
- In the Command Palette execute below command to add a docker file to the web app project.
Docker: Add Docker Files to Workspace
- Then select below when prompted
- ASP.NET Core
- Linux
- keep port as 80 and press enter
- In the Terminal window type below command to build the web app as a Docker image. -t here says to tag the image.
docker build -t akswebapp01 .
- Use below command to see the image built. The image is tagged as latest.
docker image ls
- Once the build completed you can run the web app with below command as a docker container to test it locally. -d here says to run container in detach mode. and -p says to publish the exposed ports to the host.
docker run -d -p 8090:80 akswebapp01
- Run
docker container lsto view the running containers - In a browser type http://localhost:8090 to view the web app running in the container.
- To stop the container execute
docker stop _containerid_.
- Add the two yaml files (Deploy yaml, Namespace yaml) to the project code folder, enable deployment to AKS by defining a release pipeline. Get the raw file content from GitHub and create files with same names AKSDemoDeploy.yml and AKSDemoNamespace.yml.
- To prevent adding unwanted local files such as package content or built files in bin, obj folders lets add a gitignore file. Generating gitignore file in vscode is possible by executing
Generate .gitignore Filein Command Palette. Make sure to select visualstudiocode, windows and aspnetcore. Then click OK to generate the .gitignore file. - Commit the code providing a comment.
- Push the code by clicking Push.
- Copy row content of build template file AKS-CI.json from here and create a file named AKS-CI.json.
- Follow the instructions in the post here and replace the value be283114-c5da-4df5-be57-86ac200da20f all occurrences with the team project key of your team project, using a notepad. Then save the AKS-CI.json and import the build definition to your team project.
- In the imported definition change the agent pool to Ubuntu 1604.
- Add your Azure subscription to Docker build and Docker push steps and select the container registry you have created with Azure DevOps projects exercise.
- Save the build definition and queue it.
- Once the build done inspect the container registry and you would see the built docker image is added their tagged with the build id.
- Copy row content of release template file AKS-CD.json from here and create a file named AKS-CD.json.
- Follow the instructions in the post here and replace the value 2f3e3d6e-6b7d-46cb-b65a-27c396261aff all occurrences with the team project key of your team project, using a notepad. Then save the AKS-CD.json and import the release definition to your team project.
- Remove the two artifacts in the pipeline and Add the new build as an artifact with continuous deployment enabled.
- Add the team project git repo as an artifact.
- In the variables tab change the ACR variable value to use the Azure Container Registry log on server. You can copy it from Azure portal in overview page of the Azure Container Registry. Other variable values you do not have to change as long as you are using the build definition created earlier with the given instructions as artifact in the release pipeline.
- As the agent to execute release steps select hosted vs 2017 pool.
- In the replace tokens step select the git repo artifact path which contains the yaml files (AKSDemoDeploy.yml, AKSDemoNamespace.yml).
- In the kubectl apply Namespace step, select the Azure subscription and select the kubernetes cluster and the resource group of the kubernetes cluster. Make sure to keep namespace empty as this is the step creating namespace if it is not existing.
- Change the path to the AKSDemoNamespace.yml in your repo added as artifact to the release pipeline. Expand the secrets and select the Azure sbscription and the container registry. You can keep the secret empty.
- In the kubectl apply step, select Azure subscription cluster name and resource group of the cluster. Make sure the namespace variable is used.
- Change the path to the AKSDemoDeploy.yml in your repo added as artifact to the release pipeline. Expand the secrets and select the Azure subscription and the container registry. make sure to provide the secret variable here to enable the pod deployment to access image in Azure container registry.
- Save and create a release.
- Once release completed use the Kuberenetes dashboard and select the demodev namespace. You would see the web app is running and you can verify accessing it using the external endpoint.