This topic describes how to use Bamboo to deploy a remote agent in a Container Service
for Kubernetes (ACK) cluster and run a build plan for an application. In this topic,
a sample application compiled in Java is created and deployed in an ACK cluster.
Source code
Address of the GitHub project in this example:
https://github.com/AliyunContainerService/jenkins-demo.git
The source code under the bamboo
branch is used.
Step 1: Deploy a remote agent in an ACK cluster
- Create a Secret named kaniko-docker-cfg.
The kaniko-docker-cfg Secret is used to authenticate access to an image registry when
you run a build plan and push an image to the image registry.
- Log on to your Linux server as a root user and run the following command to generate the /root/.docker/config.json file:
docker login registry.cn-hangzhou.aliyuncs.com
- Use Cloud Shell to connect to the created ACK cluster. Run the following command to create the kaniko-docker-cfg
Secret:
kubectl -n bamboo create secret generic kaniko-docker-cfg --from-file=/root/.docker/config.json
- Deploy the Bamboo agent.
Create a service account and ClusterRoleBinding to configure permissions of the Bamboo
agent in the ACK cluster.
- Create a file named bamboo-agent.yaml and copy the following content to the file. Run the
kubectl -n bamboo apply -f bamboo-agent.yaml
command to deploy the Bamboo agent. apiVersion: v1
kind: ServiceAccount
metadata:
namespace: bamboo
name: bamboo
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: bamboo-cluster-admin
subjects:
- kind: ServiceAccount
name: bamboo
namespace: bamboo
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bamboo-agent
spec:
replicas: 1
selector:
matchLabels:
app: bamboo-agent
template:
metadata:
labels:
app: bamboo-agent
spec:
serviceAccountName: bamboo
containers:
- name: bamboo-agent
env:
- name: BAMBOO_SERVER_URL
value: http://xx.xx.xx.xx:8085
image: registry.cn-hangzhou.aliyuncs.com/haoshuwei/docker-bamboo-agent:v1
imagePullPolicy: Always
volumeMounts:
- mountPath: /root/.docker/
name: kaniko-docker-cfg
volumes:
- name: kaniko-docker-cfg
secret:
secretName: kaniko-docker-cfg
- After the Bamboo agent is deployed, run the following command to query the log data
of the agent:
kubectl -n bamboo logs -f <bamboo agent pod name>
Note Replace bamboo agent pod name with the actual pod name.
- After the remote agent is deployed, log on to the Bamboo console. In the upper-right corner of the console, click
and select Agent from the drop-down list.
On the Bamboo administration page, you can find the deployed agent.

Step 2: Configure a build plan
You can configure a build plan to pull the source code, compile and package the source
code, package and push the container image, and deploy the application.
- Create a build plan.
- Log on to the Bamboo console, choose to go to the Configure plan page.
- Select bamboo-ack-demo from the Project drop-down list. Set Plan name, Plan key, and Plan description. Select java-demo from the Repository host drop-down list. Then, click Configure plan.
- The Configure Job page appears. On the Configure Job page, configure the stages and add jobs.
- Pull the source code.
When you create the build plan, you have selected java-demo from the Repository host drop-down list. This means that you have configured from where to pull the source
code. If you want to change the code repository, perform the following steps.
- In the Create tasks section, click Source Code Checkout.

- In the Source Code Checkout configuration panel, modify Repository host based on your requirements and click Save.
- Use Maven to package the source code.
- In the Create tasks section, click Add task. In the Task types dialog box, select Command.

- In the Command configuration panel, set Task description, Executable, and Argument. Click Save.

- Use kaniko to package and push the container image to the image registry.
- In the Create tasks section, click Add task. In the Task types dialog box, select Script.

- In the Script configuration panel, set Task description and Script location. Use the default settings for the other parameters. Click Save.

In this example,
Script location is specified as:
kaniko -f `pwd`/Dockerfile -c `pwd` --destination=registry.cn-hangzhou.aliyuncs.com/haoshuwei/bamboo-java-demo:latest
- Use kubectl to deploy the application in the ACK cluster.
- In the Create tasks section, click Add task. In the Task types dialog box, select Script.

- In the Script configuration panel, set Task description and Script location. Use the default settings for the other parameters. Click Save.

In this example,
Script location is specified as:
sed -i 's#IMAGE_URL#registry.cn-hangzhou.aliyuncs.com/haoshuwei/bamboo-java-demo:latest#' ./*.yaml
kubectl apply -f ./
- Run the build plan.
- After you have completed the preceding steps, click Create. The bamboo-ack-demo page appears.
- In the upper-right corner of the bamboo-ack-demo page, choose to run the newly created build plan.

You can also click the
Logs tab to view the log of the build plan.

- Access the application.
- Run the
kubectl -n bamboo get svc
command to query information about the Service for the deployed application. [root@iZbp12i73koztp1cz75skaZ bamboo]# kubectl -n bamboo get svc
Expected output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
jenkins-java-demo LoadBalancer xx.xx.xx.xx xx.xx.xx.xx 80:32668/TCP 39m
- You can enter http://EXTERNAL-IP into the address bar of your browser to access the deployed application.
References
For more information about how to build the registry.cn-hangzhou.aliyuncs.com/haoshuwei/docker-bamboo-agent:v1
image, see docker-bamboo-agent.
For more information about Bamboo, see Bamboo.