github.com/qsunny/k8s@v0.0.0-20220101153623-e6dca256d5bf/examples-master/staging/newrelic-infrastructure/README.md (about) 1 ## New Relic Infrastructure agent Example 2 3 This example shows how to run a New Relic Infrastructure agent as a pod in a DaemonSet on an existing Kubernetes cluster. 4 5 This example will create a DaemonSet which places the New Relic Infrastructure agent on every node in the cluster. It's also fairly trivial to exclude specific Kubernetes nodes from the DaemonSet to just monitor specific servers. (The prior nrsysmond has been deprecated.) 6 7 ### Step 0: Prerequisites 8 9 This process will create privileged containers which have full access to the host system for logging. Beware of the security implications of this. 10 11 DaemonSets must be enabled on your cluster. Instructions for enabling DaemonSet can be found [here](../../docs/api.md#enabling-the-extensions-group). 12 13 ### Step 1: Configure New Relic Infrastructure Agent 14 15 The New Relic Infrastructure agent is configured via environment variables. We will configure these environment variables in a sourced bash script, encode the environment file data, and store it in a secret which will be loaded at container runtime. (Reread this sentence a few times, it's *HOW* the entire container works.) 16 17 The [New Relic Infrastructure agent configuration page](https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/configuration/configure-infrastructure-agent) lists all the other settings for the Infrastructure process. 18 19 To create an environment variable for a setting, prepend NRIA_ to its name and capitalize all of the env variable. For example, 20 21 ```console 22 log_file=/var/log/nr-infra.log 23 ``` 24 25 translates to 26 27 ```console 28 NRIA_LOG_FILE=/var/log/nr-infra.log 29 ``` 30 31 Edit examples/newrelic-infrastructure/nrconfig.env and configure relevant environment variables for your NewRelic Infrastructure agent. There are a few defaults defined, but the only required variable is the New Relic license key. 32 33 Now, let's vendor the config into a secret. 34 35 ```console 36 $ cd examples/newrelic-infrastructure/ 37 $ ./config-to-secret.sh 38 ``` 39 40 <!-- BEGIN MUNGE: EXAMPLE newrelic-config-template.yaml --> 41 42 ```yaml 43 apiVersion: v1 44 kind: Secret 45 metadata: 46 name: newrelic-config 47 type: Opaque 48 data: 49 config: {{config_data}} 50 ``` 51 52 [Download example](newrelic-config-template.yaml?raw=true) 53 <!-- END MUNGE: EXAMPLE newrelic-config-template.yaml --> 54 55 The script will encode the config file and write it to `newrelic-config.yaml`. 56 57 Finally, submit the config to the cluster: 58 59 ```console 60 $ kubectl create -f examples/newrelic-infrastructure/newrelic-config.yaml 61 ``` 62 63 ### Step 2: Create the DaemonSet definition. 64 65 The DaemonSet definition instructs Kubernetes to place a newrelic Infrastructure agent on each Kubernetes node. 66 67 <!-- BEGIN MUNGE: EXAMPLE newrelic-infra-daemonset.yaml --> 68 69 ```yaml 70 apiVersion: extensions/v1beta1 71 kind: DaemonSet 72 metadata: 73 name: newrelic-infra-agent 74 labels: 75 tier: monitoring 76 app: newrelic-infra-agent 77 version: v1 78 spec: 79 template: 80 metadata: 81 labels: 82 name: newrelic 83 spec: 84 # Filter to specific nodes: 85 # nodeSelector: 86 # app: newrelic 87 hostPID: true 88 hostIPC: true 89 hostNetwork: true 90 containers: 91 - resources: 92 requests: 93 cpu: 0.15 94 securityContext: 95 privileged: true 96 image: newrelic/infrastructure 97 name: newrelic 98 command: [ "bash", "-c", "source /etc/kube-nr-infra/config && /usr/bin/newrelic-infra" ] 99 volumeMounts: 100 - name: newrelic-config 101 mountPath: /etc/kube-nr-infra 102 readOnly: true 103 - name: dev 104 mountPath: /dev 105 - name: run 106 mountPath: /var/run/docker.sock 107 - name: log 108 mountPath: /var/log 109 - name: host-root 110 mountPath: /host 111 readOnly: true 112 volumes: 113 - name: newrelic-config 114 secret: 115 secretName: newrelic-config 116 - name: dev 117 hostPath: 118 path: /dev 119 - name: run 120 hostPath: 121 path: /var/run/docker.sock 122 - name: log 123 hostPath: 124 path: /var/log 125 - name: host-root 126 hostPath: 127 path: / 128 ``` 129 130 [Download example](newrelic-infra-daemonset.yaml?raw=true) 131 <!-- END MUNGE: EXAMPLE newrelic-infra-daemonset.yaml --> 132 133 The daemonset instructs Kubernetes to spawn pods on each node, mapping /dev/, /run/, and /var/log to the container. It also maps the entire kube node / to /host/ in the container with a read-only mount. It also maps the secrets we set up earlier to /etc/kube-newrelic/config, and sources them in the startup script, configuring the agent properly. 134 135 #### DaemonSet customization 136 137 - There are more environment variables for fine tuning the infrastructure agent's operation (or a yaml file that you'd have to construct). See [Infrastructure Agent Environment Variables](https://docs.newrelic.com/docs/infrastructure/new-relic-infrastructure/configuration/configure-infrastructure-agent) for the full list. 138 139 140 ### Known issues 141 142 It's a bit cludgy to define the environment variables like we do here in these config files. There is [another issue](https://github.com/kubernetes/kubernetes/issues/4710) to discuss adding mapping secrets to environment variables in Kubernetes. (Personally I don't like that method and prefer to use the config secrets.) 143 144 <!-- BEGIN MUNGE: GENERATED_ANALYTICS --> 145 []() 146 <!-- END MUNGE: GENERATED_ANALYTICS -->