This page describes how to use the init containers option to copy agent files into a Kubernetes® application container at deploy time.
The init containers option is available in Kubernetes environments used to run additional containers at startup that helps initialize an application. Once the init containers have completed their initialization tasks, they terminate but leave the application container(s) running. For the App Server Agent installation, init containers are used as a delivery mechanism to copy the agent files into the application container at deploy time. See Init Containers Option in Kubernetes.
Copying the agent files at deploy time (instead of at build time) provides advantages over explicitly copying the agent files and dependencies into the application image. The init containers option simplifies the image build process because:
- You do not need to update each application's Dockerfile to copy the agent files.
- You do not need to rebuild the application image for agent upgrades.
See the language-specific container installation page for how to use an init container:
Kubernetes Init Container Deployment Spec Example
In the Kubernetes deployment spec example for a Java application, the init container is a second Docker image that contains the App Server Agent files. Because this Docker image is built separately from the application image, you do not need to rebuild the application image when you add or upgrade the App Server Agent.
kind: Deployment
spec:
containers:
-
image: "repo/java-app:v1"
name: java-app
volumeMounts:
-
mountPath: /opt/appdynamics
name: appd-agent-repo
initContainers:
-
command:
- cp
- "-ra"
- /opt/appdynamics/.
- /opt/temp
image: "docker.io/appdynamics/java-agent:20.6.0"
n ame: appd-agent
volumeMounts:
-
mountPath: /opt/temp
name: appd-agent-repo
volumes:
-
emptyDir: {}
name: appd-agent-repo
YML
Dockerfile Example
In this example for a Java application, the Java Agent files in the AppServerAgent
folder are copied to the application image and the application JAR file. The agent environment variables are set before the start script runs.
FROM openjdk:8-jre-slim
COPY myapp.jar /app
COPY AppServerAgent/ /opt/appdynamics
ENV APPDYNAMICS_AGENT_APPLICATION_NAME=<value>
ENV APPDYNAMICS_AGENT_TIER_NAME=<value>
ENV APPDYNAMICS_AGENT_ACCOUNT_NAME=<value>
ENV APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY=<value>
ENV APPDYNAMICS_CONTROLLER_HOST_NAME=<value>
ENV APPDYNAMICS_CONTROLLER_PORT=<value>
ENV APPDYNAMICS_CONTROLLER_SSL_ENABLED=<value>
ENV APPDYNAMICS_JAVA_AGENT_REUSE_NODE_NAME=true
ENV APPDYNAMICS_JAVA_AGENT_REUSE_NODE_NAME_PREFIX=<value>
COPY ./startup.sh /startup.sh
RUN chmod +x /startup.sh
ENTRYPOINT ["/bin/bash", "/startup.sh"]
CODE
Kubernetes® is a trademark of The Linux Foundation®.