This document describes how to use the local image cache mode to speed up ack-onepilot integration for Java applications.
Background
By default, to ensure flexible application integration, the init-container injected by the ack-onepilot component dynamically pulls the required version of the agent package based on specific rules. However, pulling the agent package on the fly can cause issues in some scenarios:
-
In edge scenarios with poor network connectivity, pulling the agent package can take significantly longer and might even fail due to timeouts.
-
Integrating many applications at once can increase the host's IOPS, consuming significant I/O resources over a short period.
Prerequisites
-
ack-onepilot version 5.1.0 or later.
-
The application is written in Java.
-
The agent version is 4.2.5 or later.
Procedure
This example YAML manifest shows how a simple Java application in Kubernetes can use the local image cache mode to speed up ack-onepilot integration.
Example application YAML
apiVersion: v1
kind: Namespace
metadata:
name: arms-demo
---
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: arms-springboot-demo
namespace: arms-demo
labels:
app: arms-springboot-demo
spec:
replicas: 2
selector:
matchLabels:
app: arms-springboot-demo
template:
metadata:
labels:
app: arms-springboot-demo
armsPilotAutoEnable: "on"
armsPilotCreateAppName: "arms-k8s-demo"
# Required. Enable local image cache mode.
apsara.apm/enable-cached-agent: 'true'
# Required for local image cache mode. Specify the agent version. You can replace this with the version you need.
aliyun.com/agent-version: 4.2.5
spec:
containers:
- resources:
limits:
cpu: 0.5
image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-springboot-demo:v0.1
imagePullPolicy: Always
name: arms-springboot-demo
env:
- name: SELF_INVOKE_SWITCH
value: "true"
- name: COMPONENT_HOST
value: "arms-demo-component"
- name: COMPONENT_PORT
value: "6666"
- name: MYSQL_SERVICE_HOST
value: "arms-demo-mysql"
- name: MYSQL_SERVICE_PORT
value: "3306"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: arms-springboot-demo-subcomponent
namespace: arms-demo
labels:
app: arms-springboot-demo-subcomponent
spec:
replicas: 2
selector:
matchLabels:
app: arms-springboot-demo-subcomponent
template:
metadata:
labels:
app: arms-springboot-demo-subcomponent
armsPilotAutoEnable: "on"
armsPilotCreateAppName: "arms-k8s-demo-subcomponent"
# Required. Enable local image cache mode.
apsara.apm/enable-cached-agent: 'true'
# Required for local image cache mode. Specify the agent version. You can replace this with the version you need.
aliyun.com/agent-version: 4.2.5
spec:
containers:
- resources:
limits:
cpu: 0.5
image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-springboot-demo:v0.1
imagePullPolicy: Always
name: arms-springboot-demo-subcomponent
env:
- name: SELF_INVOKE_SWITCH
value: "false"
- name: MYSQL_SERVICE_HOST
value: "arms-demo-mysql"
- name: MYSQL_SERVICE_PORT
value: "3306"
---
apiVersion: v1
kind: Service
metadata:
labels:
name: arms-demo-component
name: arms-demo-component
namespace: arms-demo
spec:
ports:
# the port that this service should serve on
- name: arms-demo-component-svc
port: 6666
targetPort: 8888
# label keys and values that must match in order to receive traffic for this service
selector:
app: arms-springboot-demo-subcomponent
---
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: arms-demo-mysql
namespace: arms-demo
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- resources:
limits:
cpu: 0.5
image: registry.cn-hangzhou.aliyuncs.com/arms-docker-repo/arms-demo-mysql:v0.1
name: mysql
ports:
- containerPort: 3306
name: mysql
---
apiVersion: v1
kind: Service
metadata:
labels:
name: mysql
name: arms-demo-mysql
namespace: arms-demo
spec:
ports:
# the port that this service should serve on
- name: arms-mysql-svc
port: 3306
targetPort: 3306
# label keys and values that must match in order to receive traffic for this service
selector:
app: mysql
---
-
Install ack-onepilot and grant it the necessary resource access permissions. For detailed instructions, see Install the ARMS agent assistant (ack-onepilot).
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
-
On the Stateless page, find your application, and in the Actions column, choose .
To create a new application, click Create From YAML.
-
In the YAML editor, add the following labels under spec.template.metadata, and then click Update.
labels:
armsPilotAutoEnable: "on"
armsPilotCreateAppName: "arms-k8s-demo-subcomponent"
# Required. Enable local image cache mode.
apsara.apm/enable-cached-agent: 'true'
# Required for local image cache mode. Specify the agent version. You can replace this with the version you need. For a list of released agent versions, see the agent management documentation.
aliyun.com/agent-version: 4.2.5
aliyun.com/app-language: java
-
On the Stateless page, find your application and click in the Actions column to view its monitoring details.