You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
3.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # Kubernetes CI/CD VSTS
  2. For k8s CI/CD pipeline delivery a series of tasks must be created in VSTS to deploy k8s in Azure
  3. ## Prerequisites
  4. * A Kubernetes cluster. Follow Azure Container Service's [walkthrough](https://docs.microsoft.com/en-us/azure/container-service/container-service-kubernetes-walkthrough) to create one.
  5. * A private Docker registry. Follow Azure Container Registry's [guide](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal) to create one.
  6. * Optionally, previous steps can be skipped if you run gen-k8s-env.ps1 script to automatically create the azure environment needed for kubernetes deployment. Azure cli 2.0 must be previously installed [installation guide](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli). For example:
  7. >```
  8. >./gen-k8s-env -resourceGroupName k8sGroup -location westeurope -registryName k8sregistry -orchestratorName k8s-cluster -dnsName k8s-dns
  9. >```
  10. * An `Azure Blob storage`. It is needed for storing the kubernetes config file used by the hosted agent to access to Kubernetes cluster. Example:
  11. <img src="./img/k8s/blob_creation.png">
  12. * Upload the `kubernetes config file` to the blob storage previously created. Execute the following command which will download the config file into the directory `c:\Users\<User>\.kube\` and then, upload it to your blob storage:
  13. >```
  14. >https://eshopk8s.blob.core.windows.net/k8s-config/config
  15. >```
  16. ## Create the VSTS tasks
  17. 1. Create a `Download File` task to download the kubernetes binary `kubectl` to the hosted agent. For example:
  18. >```
  19. >https://storage.googleapis.com/kubernetes-release/release/v0.0.1.7.0-alpha.0/bin/windows/386/kubectl.exe
  20. >```
  21. <img src="./img/get_kubectlbin_task.png">
  22. 2. Create a Download File task to download the kubernetes config file to the hosted agent. For example:
  23. >```
  24. >https://eshopk8s.blob.core.windows.net/k8s-config/config
  25. >```
  26. <img src="./img/k8s/get_kubectlconfig_task.png">
  27. 3. Create a powershell task to execute the k8s deployment script. For example:
  28. * Deployment script path
  29. >```
  30. >$(System.DefaultWorkingDirectory)/All Microservices/docker-compose/deploy.ps1
  31. >```
  32. * Deployment script path arguments. Use value:
  33. >```
  34. >-deployCI $true -execPath '$(System.DefaultWorkingDirectory)/' -kubeconfigPath '$(System.DefaultWorkingDirectory)/' -deployInfrastructure $true -imageTag dev -configFile '$(System.DefaultWorkingDirectory)/$(Build.DefinitionName)/docker-compose/conf_local.yml'
  35. >```
  36. - deployCI: Must be set to `$true`. This avoids create images (always are pulled from registry) and compile bits.
  37. - deployInfrastructure: Can be set to `$false` if don't want to deploy infrastructure containers (like Redis, rabbit, SQL,...).
  38. - imageTag: Image tag to pull from k8s.
  39. - configFile: Configuration file (refer to [README.k8s.md](./README.k8s.md) for more info). This file is part of the VSTS build output.
  40. - execPath: path where the k8s binary is stored
  41. - kubeconfigPath: path where the k8s config file is stored
  42. You can use additional parameters (i.e. pass registry and user/password to use custom registry instead of DockerHub. Plase, refer to [README.k8s.md](./README.k8s.md) for more info.
  43. <img src="./img/k8s/deploy_script_task.png">