This sample is shows how to bake your docker image, push image to docker hub,create aks cluster with terraform and deploy containers to k8s cluster.
- Azure Subscription: If you don’t have an Azure subscription, you can create a free account at https://azure.microsoft.com before start.
- Azure Service Principal: is an identity used to authenticate to Azure. Below are the instructions to create one
- Azure DevOps Account: Create an Azure DevOps account because is a separate service from the Azure Portal
- Terraform extension: Install the Terraform Build & Release Tasks extension from the Marketplace
First of all, you have to do two things.
- Fork this repositroy
- Create a service connection for uploading Docker images to a Docker Hub private repository
Open the Project, then click Project settings, then click Service connections.Select registry type the Docker Hub and then enter the Docker Hub ID, password,email address and give the connection a meaningful.Click save and verify this connection.
Now we are ready to build our first Azure DevOps Build Pipeline
Click on the build pipeline button and select GitHub yaml
Select the k8schallenge repository
Select an Existing Azure Pipelines Yaml file
Then select /02-sampleapp/ci/azure-pipelines.yml path
Click at the Docker@2 task settings in yaml editor and then change containerRegistry and repository name in YAML file.
Then click the Save and run button to launch our pipeline.
Follow the steps above.The only difference is the file path (/01-terraform/ci/create-infrastructure.yml)
Change subscriptions for all Azure tasks and click on the authorize button.
Don't forget to change environment variables!!
Then click the Save and run button to launch our pipeline
Follow the steps above.The only difference is the file path (/03-k8sdeployment/ci/azure-pipelines.yml)
You need to change subscription
We run all pipelines in sequence
You can also see a live feed of the console
As you can see all infrastructure, images, and applications are delivered automatically.
We will start a container, and send an infinite loop of queries to the sampleappservice
kubectl run -it --rm load-generator --image=busybox /bin/sh
while true; do wget -q -O- http://40.118.127.126:11130; done
You will see the number of pods increases after the load.
End of the day don't forget to remove infrastructure. Keep Your Money in Your Pocket !!
Bonus : You can use delete-infrastructure.yml for this task.
Everything's gone