You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by sz...@apache.org on 2022/07/19 12:37:18 UTC

[nifi-minifi-cpp] 02/03: MINIFICPP-1880 Address documentation issues of daemonset deployment

This is an automated email from the ASF dual-hosted git repository.

szaszm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git

commit 6f9419783f22d8c6b22627aebdb21651f07278a9
Author: Gabor Gyimesi <ga...@gmail.com>
AuthorDate: Tue Jul 19 13:56:06 2022 +0200

    MINIFICPP-1880 Address documentation issues of daemonset deployment
    
    Closes #1366
    Signed-off-by: Marton Szasz <sz...@apache.org>
---
 examples/kubernetes/README.md                          | 12 ++++++++----
 .../cluster-roles/daemon.namespace.yml                 |  6 ++++++
 .../cluster-roles/namespace-reader.clusterrole.yml     |  9 +++++++++
 .../namespace-reader.clusterrolebinding.yml            | 12 ++++++++++++
 .../cluster-roles/pod-reader.clusterrole.yml           |  9 +++++++++
 .../cluster-roles/pod-reader.clusterrolebinding.yml    | 12 ++++++++++++
 .../daemon-set-log-collection.yml                      | 18 +++++++++++++-----
 .../sidecar-log-collection.yml                         |  0
 8 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/examples/kubernetes/README.md b/examples/kubernetes/README.md
index 1ff7a47b2..028505a24 100644
--- a/examples/kubernetes/README.md
+++ b/examples/kubernetes/README.md
@@ -18,13 +18,17 @@ The following examples show different configurations that can be applied in Kube
 
 ## Cluster level log collection with MiNiFi C++
 
-The [daemon-set-log-collection.yml](daemon-set-log-collection.yml) file has an example for cluster level log collection, which is done on every node by creating a daemon set.
+The [daemon-set-log-collection.yml](daemon-set-log-collection/daemon-set-log-collection.yml) file has an example for cluster level log collection, which is done on every node by creating a daemon set.
 The config includes a KubernetesControllerService that provides the namespace, pod, uid, container variables for the TailFile processor for getting the logs for the filtered Kubernetes objects.
 In this specific example all container logs from the default namespace are collected and forwarded to Kafka.
 The controller service can be modified to have additional filters for namespaces, pods, containers, for which more information can be found in the [CONTROLLERS.md](/CONTROLLERS.md#kubernetesControllerService) documentation.
-This setup complies with the ["node logging agent"](https://kubernetes.io/docs/concepts/cluster-administration/logging/#using-a-node-logging-agent) architecture described in the Kubernetes documentation.
+
+Note: To query Kubernetes cluster information, the MiNiFi agent requires read permission on the pod and namespace objects. One way to give read access to MiNiFi is to create specific cluster roles and cluster role bindings for a specific namespace where the MiNiFi is deployed. There is an example on this in the [daemon-set-log-collection/cluster-roles](daemon-set-log-collection/cluster-roles) directory.
+
+This setup complies with the [node logging agent](https://kubernetes.io/docs/concepts/cluster-administration/logging/#using-a-node-logging-agent) architecture described in the Kubernetes documentation.
 
 ## Pod level log collection with sidecar container using MiNiFi C++
 
-The [sidecar-log-collection.yml](sidecar-log-collection.yml) file has an example for pod level log collection, which is done by creating a sidecar container in the same pod where the container we want to collect the logs from is present. In this specific example a pod with a NiFi container is instantiated with a MiNiFi sidecar container which collects, compresses and uploads the NiFi logs to an AWS S3 bucket.
-This setup complies with the ["sidecar container with logging agent"](https://kubernetes.io/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent) architecture described in the Kubernetes documentation.
+The [sidecar-log-collection.yml](sidecar-log-collection/sidecar-log-collection.yml) file has an example for pod level log collection, which is done by creating a sidecar container in the same pod where the container we want to collect the logs from is present. In this specific example a pod with a NiFi container is instantiated with a MiNiFi sidecar container which collects, compresses and uploads the NiFi logs to an AWS S3 bucket.
+
+This setup complies with the [sidecar container with logging agent](https://kubernetes.io/docs/concepts/cluster-administration/logging/#sidecar-container-with-logging-agent) architecture described in the Kubernetes documentation.
diff --git a/examples/kubernetes/daemon-set-log-collection/cluster-roles/daemon.namespace.yml b/examples/kubernetes/daemon-set-log-collection/cluster-roles/daemon.namespace.yml
new file mode 100644
index 000000000..f628b21e6
--- /dev/null
+++ b/examples/kubernetes/daemon-set-log-collection/cluster-roles/daemon.namespace.yml
@@ -0,0 +1,6 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: daemon
+  labels:
+    name: daemon
diff --git a/examples/kubernetes/daemon-set-log-collection/cluster-roles/namespace-reader.clusterrole.yml b/examples/kubernetes/daemon-set-log-collection/cluster-roles/namespace-reader.clusterrole.yml
new file mode 100644
index 000000000..863439a69
--- /dev/null
+++ b/examples/kubernetes/daemon-set-log-collection/cluster-roles/namespace-reader.clusterrole.yml
@@ -0,0 +1,9 @@
+kind: ClusterRole
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  namespace: default
+  name: namespace-reader
+rules:
+- apiGroups: [""]  # "" indicates the core API group
+  resources: ["namespaces"]
+  verbs: ["get", "watch", "list"]
diff --git a/examples/kubernetes/daemon-set-log-collection/cluster-roles/namespace-reader.clusterrolebinding.yml b/examples/kubernetes/daemon-set-log-collection/cluster-roles/namespace-reader.clusterrolebinding.yml
new file mode 100644
index 000000000..98de6c481
--- /dev/null
+++ b/examples/kubernetes/daemon-set-log-collection/cluster-roles/namespace-reader.clusterrolebinding.yml
@@ -0,0 +1,12 @@
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: namespace-reader-binding
+subjects:
+- kind: ServiceAccount
+  name: default
+  namespace: daemon
+roleRef:
+  kind: ClusterRole
+  name: namespace-reader
+  apiGroup: rbac.authorization.k8s.io
diff --git a/examples/kubernetes/daemon-set-log-collection/cluster-roles/pod-reader.clusterrole.yml b/examples/kubernetes/daemon-set-log-collection/cluster-roles/pod-reader.clusterrole.yml
new file mode 100644
index 000000000..a83231487
--- /dev/null
+++ b/examples/kubernetes/daemon-set-log-collection/cluster-roles/pod-reader.clusterrole.yml
@@ -0,0 +1,9 @@
+kind: ClusterRole
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  namespace: default
+  name: pod-reader
+rules:
+- apiGroups: [""]  # "" indicates the core API group
+  resources: ["pods"]
+  verbs: ["get", "watch", "list"]
diff --git a/examples/kubernetes/daemon-set-log-collection/cluster-roles/pod-reader.clusterrolebinding.yml b/examples/kubernetes/daemon-set-log-collection/cluster-roles/pod-reader.clusterrolebinding.yml
new file mode 100644
index 000000000..1d32a1933
--- /dev/null
+++ b/examples/kubernetes/daemon-set-log-collection/cluster-roles/pod-reader.clusterrolebinding.yml
@@ -0,0 +1,12 @@
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: pod-reader-binding
+subjects:
+- kind: ServiceAccount
+  name: default
+  namespace: daemon
+roleRef:
+  kind: ClusterRole
+  name: pod-reader
+  apiGroup: rbac.authorization.k8s.io
diff --git a/examples/kubernetes/daemon-set-log-collection.yml b/examples/kubernetes/daemon-set-log-collection/daemon-set-log-collection.yml
similarity index 92%
rename from examples/kubernetes/daemon-set-log-collection.yml
rename to examples/kubernetes/daemon-set-log-collection/daemon-set-log-collection.yml
index ce2d63ee1..0f1c351a6 100644
--- a/examples/kubernetes/daemon-set-log-collection.yml
+++ b/examples/kubernetes/daemon-set-log-collection/daemon-set-log-collection.yml
@@ -65,7 +65,7 @@ data:
         Client Name: test-client
         Compress Codec: none
         Delivery Guarantee: '1'
-        Known Brokers: kafka-broker:9092
+        Known Brokers: kafka-service.default.svc.cluster.local:9092
         Message Timeout: 12 sec
         Request Timeout: 10 sec
         Topic Name: ${kubernetes.namespace}_${kubernetes.pod}_${kubernetes.container}_logs
@@ -87,16 +87,18 @@ metadata:
   labels:
     k8s-app: minifi-log-collection
   name: minifi-log-collection-config
-  namespace: default
+  namespace: daemon
 ---
 apiVersion: apps/v1
 kind: DaemonSet
 metadata:
   name: log-collection-minifi
-  namespace: default
+  namespace: daemon
   labels:
     k8s-app: minifi-log-collection
 spec:
+  securityContext:
+    runAsUser: 0
   selector:
     matchLabels:
       name: log-collection-minifi
@@ -108,6 +110,8 @@ spec:
       containers:
       - name: minifi
         image: apache/nifi-minifi-cpp:latest
+        securityContext:
+          allowPrivilegeEscalation: false
         volumeMounts:
         - name: minificonfig
           mountPath: /opt/minifi/minifi-current/conf/config.yml
@@ -115,10 +119,14 @@ spec:
         - name: minificonfig
           mountPath: /opt/minifi/minifi-current/conf/minifi-log.properties
           subPath: minifi-log.properties
+        - name: var-log-pods
+          mountPath: /var/log/pods
+          readOnly: true
       volumes:
-      - name: nifi-logs
-        emptyDir: {}
       - configMap:
           defaultMode: 420
           name: minifi-log-collection-config
         name: minificonfig
+      - name: var-log-pods
+        hostPath:
+          path: /var/log/pods
diff --git a/examples/kubernetes/sidecar-log-collection.yml b/examples/kubernetes/sidecar-log-collection/sidecar-log-collection.yml
similarity index 100%
rename from examples/kubernetes/sidecar-log-collection.yml
rename to examples/kubernetes/sidecar-log-collection/sidecar-log-collection.yml