开发者openshift4使用入门教程 - 16 - 使用init container挂载pinpoint APM监控

2022-04-21 14:19:42 浏览数 (1)

tomcat容器安装pinpoint-agent

  • [ 准备initcontainers镜像]

Dockerfile文件(参照镜像标准编写)

代码语言:javascript复制
FROM alpine:latest
LABEL io.openshift.tags="pinpoint-agent"
RUN mkdir /pinpoint-agent 
 && chmod -R u x /pinpoint-agent 
 && chmod -R g=u /pinpoint-agent /etc/passwd
ADD pinpoint-agent-1.8.4.tar.gz /pinpoint-agent/
CMD ["tail", "-f", "/dev/null"]
  • [ 更新yaml文件]
代码语言:javascript复制
      volumes:
        - name: pinpoint-agent-1
          emptyDir: {}
      initContainers:
        - name: pinpoint-agent
          image: >-
            image-registry.openshift-image-registry.svc:5000/pinpoint-agent-test/pinpoint-agent@sha256:4d703d7471e98eb4d66c6e76dc1079d536d7fc746d1a1b6f11e23514c7afde6d
          command: ["sh", "-c", "cp -r /pinpoint-agent/* /deployments-pinpoint-agent"]
          resources: {}
          volumeMounts:
            - name: pinpoint-agent-1
              mountPath: /deployments-pinpoint-agent

首先定义一个emptyDir类型的卷pinpoint-agent-1,initcontainers容器启动的时候,将这个pinpoint-agent-1卷挂载到/sharedFiles/AppServerAgent目录,并把容器镜像层中的/pinpoint-agent目录下的文件拷贝到pinpoint-agent-1卷下面,然后initContainers的使命完成,正常退出。

代码语言:javascript复制
containers:
        - resources: {}
          readinessProbe:
            exec:
              command:
                - /bin/bash
                - '-c'
                - >-
                  curl --noproxy '*' -s -u J8KQ7u87:BxgGot20
                  'http://localhost:8080/manager/jmxproxy/?get=Catalina:type=Server&att=stateName'
                  |grep -iq 'stateName *= *STARTED'
            timeoutSeconds: 1
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          terminationMessagePath: /dev/termination-log
          name: jws-app
          env:
            - name: JWS_ADMIN_USERNAME
              value: J8KQ7u87
            - name: JWS_ADMIN_PASSWORD
              value: BxgGot20
            - name: PINPOINT_VERSION
              value: 1.8.4
            - name: AGENT_ID
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: PROJECT_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: JAVA_OPTS
              value: >-
                -javaagent:/deployments-pinpoint-agent/pinpoint-bootstrap-${PINPOINT_VERSION}-SNAPSHOT.jar
                -Dpinpoint.agentId=${AGENT_ID}
                -Dpinpoint.applicationName=${PROJECT_NAME}
          ports:
            - name: jolokia
              containerPort: 8778
              protocol: TCP
            - name: http
              containerPort: 8080
              protocol: TCP
          imagePullPolicy: Always
          volumeMounts:
            - name: pinpoint-agent-1
              mountPath: /deployments-pinpoint-agent
          terminationMessagePolicy: File
          image: >-
            image-registry.openshift-image-registry.svc:5000/pinpoint-agent-test/jws-app@sha256:3b6d7ad4c35d90ff44251ee1ff8f1fe5b3e6ebb55bf3db965d4462ea2490d83e
      restartPolicy: Always
      terminationGracePeriodSeconds: 60
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler

tomcat容器上将pod的namespace作为APP_NAME名称,将pod的name作为AGENT_ID,通过JAVA_OPTS变量配置客户端相关参数。

注:和initcontainers容器挂载相同的pinpoint-agent-1卷

0 人点赞