This document shows how to deploy this todo app java project to Kubernetes cluster using Jenkins.
You can create the Azure Services using Azure CLI 2.0.
-
login your Azure CLI, and set your subscription id
az login az account set -s <your-subscription-id>
-
Create a resource group
az group create -n <your-resource-group-name> -l westeurope
-
Create Kubernetes cluster
az acs create --orchestrator-type kubernetes -g <your-resource-group-name> -n <your-kubernetes-cluster-name> --generate-ssh-keys
-
Connect to the cluster, this command download the Kubernetes configuration to your profile folder. The kubectl will use this configure file to interact with your Kubernetes cluster.
az acs kubernetes get-credentials -g <your-resource-group-name> -n <your-kubernetes-cluster-name>
-
Install the kubectl command line
az acs kubernetes install-cli
-
login your Azure CLI, and set your subscription id
az login az account set -s <your-subscription-id>
-
Run below command to create an Azure Container Registry. After creation, use
login server
as Docker registry URL in the next section.az acr create -n <your-registry-name> -g <your-resource-group-name> --sku <sku-name> --admin-enabled true
-
Run below command to show your Azure Container Registry credentials. You will use Docker registry username and password in the next section.
az acr credential show -n <your-registry-name>
-
Deploy a Jenkins Master on Azure[https://aka.ms/jenkins-on-azure]
-
Connect to the server with SSH and install the build tools:
sudo apt-get install git maven docker.io
-
Install the plugins in Jenkins. Click 'Manage Jenkins' -> 'Manage Plugins' -> 'Available', then search and install the following plugins: EnvInject, Azure Kubernetes CD Plugin.
-
Add a Credential in type "SSH Username with private key" with your Kubernetes login credential.
-
Add a Credential in type "Username with password" with your account of docker registry.
-
Add a new job in type "Pipeline".
-
Enable "Prepare an environment for the run", and put the following environment variables in "Properties Content":
ACS_SERVER=[your Azure Container Service server] ACS_CRED_ID=[your credential id of ACS login credential] ACR_SERVER=[your Azure Container Registry] ACR_CRED_ID=[your credential id of ACR account] WEB_APP=[the name of the app] DOCUMENTDB_URI=[your documentdb uri] DOCUMENTDB_KEY=[your documentdb key] DOCUMENTDB_DBNAME=[your documentdb databasename]
-
Choose "Pipeline script from SCM" in "Pipeline" -> "Definition".
-
Fill in the SCM repo url and script path.
-
Create Kubernetes resource yaml file fragments.
- Create
src/main/jenkins/jenkins-sample.yml
with yaml content from this file. This file defines a deployment and a service with the docker image you pushed to your Azure Container Registry.
- Create
-
Verify you can run your project successfully in your local environment. (Run project on local machine)
-
Run jenkins job.
-
Get the external IP address. This may take a few minutes to wait the deploy success. Before finishing, the
external-ip
field should showpending
.kubectl get svc -w
-
Open the url you obtained in last step in your browser, you will find the todo app has been deployed to your Kubernetes cluster.
Delete the Azure resources you just created by running below command:
az group delete -y --no-wait -n <your-resource-group-name>