Fügen Sie den Node.js-Agenten in Kubernetes über InitContainers hinzu, indem Sie ein vorgefertigtes Agenten-Image nutzen.
Um den APM Insight Node.js-Agenten zu nutzen, integrieren Sie ihn mithilfe von InitContainers in Ihre Kubernetes-Anwendungen, und befolgen Sie dafür die folgenden Schritte:
Schritt 1:
Erstellen Sie ein leeres Volume, das zum Kopieren der Agent-Dateien während des InitContainers-Prozesses verwendet wird.
Beispiel:
- volumes:
- - name: app-volume
Schritt 2:
Fügen Sie den folgenden InitContainers-Befehl in Ihre Helm-Chart-/Deployment-YAML-Datei ein.
- initContainers:
- - name: init-npm
- image: site24x7/apminsight-nodejsagent:4.8.0
- imagePullPolicy: IfNotPresent
- command: ['cp', '-r', '/opt/site24x7/.', '/apm']
- volumeMounts:
- - name: app-volume
- mountPath: /apm
Schritt 3:
Übertragen Sie das in Schritt 2 hergestellte Volume in Ihren Anwendungscontainer.
Beispiel:
- containers:
- env:
- - name: NODE_OPTIONS
- value: "--require /apm/node_modules/apminsight"
- - name: APMINSIGHT_LICENSE_KEY
- value: "<license-key>"
- - name: APMINSIGHT_APP_NAME
- value: "<application-name>"
- - name: APMINSIGHT_APP_PORT
- value: "<application-port>"
- volumeMounts:
- - mountPath: /apm
- name: app-volume
Bei Anwendungen, die den PM2-Prozessmanager anstelle von Kubernetes nutzen, aktivieren Sie die PM2-Unterstützung, indem Sie Folgendes in den Abschnitt env Ihrer YAML-Deployment-Datei einfügen:
- - name: APMINSIGHT_PROCESS_MANAGER
- value: "true"
Beispiel einer YAML-Bereitstellungsdatei zu Ihrer Information:
- apiVersion: apps/v1
- kind: Bereitstellung
- metadata:
- name: sample-deployment
- spec:
- replicas: 1
- selector:
- matchLabels:
- app: sample-app
- template:
- metadata:
- labels:
- app: sample-app
- spec:
- initContainers:
- - name: init-npm
- image: site24x7/apminsight-nodejsagent:4.8.0
- imagePullPolicy: IfNotPresent
- command: ['cp', '-r', '/opt/site24x7/.', '/apm']
- volumeMounts:
- - name: app-volume
- mountPath: /apm
- containers:
- - name: main-container
- image: myrepository/sample-nodejs-app:latest
- env:
- - name: NODE_OPTIONS
- value: "--require /apm/node_modules/apminsight"
- - name: APMINSIGHT_LICENSE_KEY
- value: "<license-key>"
- - name: APMINSIGHT_APP_NAME
- value: "<application-name>"
- - name: APMINSIGHT_APP_PORT
- value: "<application-port>"
- volumeMounts:
- - mountPath: /apm
- name: app-volume
- volumes:
- - name: app-volume
- emptyDir: {}