### Kerberos Vault Ingress Configuration Example Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/README.md An example of an Ingress resource configuration for Kerberos Vault. This snippet shows how to define routing rules, specify the backend service, and configure annotations for Ingress controllers like Nginx, including TLS settings. ```yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: vault annotations: kubernetes.io/ingress.class: nginx kubernetes.io/tls-acme: "true" nginx.ingress.kubernetes.io/ssl-redirect: "true" cert-manager.io/cluster-issuer: "letsencrypt-prod" spec: rules: --> - host: vault.domain.com http: paths: - path: / backend: serviceName: vault servicePort: 80 ``` -------------------------------- ### Start Docker Compose Services Source: https://github.com/kerberos-io/vault/blob/master/docker/README.md Starts all the services defined in the docker-compose.yaml file. This command brings up Kerberos Vault, Minio, MongoDB, and Traefik. ```bash docker compose up ``` -------------------------------- ### Install Minio Operator using Krew Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/minio/README.md Installs the Minio operator using kubectl krew, a plugin manager for kubectl. Ensure krew is installed by following the official documentation. ```bash kubectl krew update kubectl krew install minio ``` -------------------------------- ### Install Kubernetes Components (Shell) Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/README.md Installs necessary packages for Kubernetes, adds the Kubernetes APT repository, and installs specific versions of kubelet, kubeadm, and kubectl. It also includes commands to disable swap memory for Kubernetes. ```shell apt update -y apt install apt-transport-https curl -y curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main" apt update -y && apt install kubelet=1.25.0-00 kubeadm=1.25.0-00 kubectl=1.25.0-00 -y swapoff -a sudo sed -i.bak '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab ``` -------------------------------- ### Install Ingress-Nginx Controller using Helm Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/README.md Installs the Ingress-Nginx controller in a Kubernetes cluster using Helm. This includes adding the Helm repository, updating repositories, creating a namespace, and performing the Helm installation. ```bash helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update kubectl create namespace ingress-nginx helm install ingress-nginx -n ingress-nginx ingress-nginx/ingress-nginx ``` -------------------------------- ### Install MetalLB Components Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/README.md Applies the necessary Kubernetes manifests to install MetalLB, including its namespace and core components. It also creates a secret required for the memberlist communication. ```bash kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.10.1/manifests/namespace.yaml kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.10.1/manifests/metallb.yaml kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey=$(openssl rand -base64 128) ``` -------------------------------- ### Apply MetalLB Configuration Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/README.md Applies the MetalLB configuration defined in a local `configmap.yaml` file to the Kubernetes cluster. This step ensures that MetalLB can start assigning IP addresses to services. ```bash kubectl apply -f ./metallb/configmap.yaml ``` -------------------------------- ### Install Docker and Configure cgroup Driver (Shell) Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/README.md Installs the docker.io package and configures the Docker daemon to use systemd for cgroup driver, which is necessary for Kubernetes compatibility. It also enables and restarts the Docker service. ```shell apt install docker.io -y sudo mkdir /etc/docker cat < node-role.kubernetes.io/control-plane- ``` -------------------------------- ### Verify Kerberos Vault Service IP Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/README.md Retrieves the service details for Kerberos Vault to confirm it has been assigned an internal or external IP address. This is crucial for accessing the application after deployment, especially when using a LoadBalancer. ```bash kubectl get svc -n kerberos-vault ``` -------------------------------- ### Verify Kafka Deployment Status Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/kafka/README.md Checks the status of Kafka and Zookeeper pods deployed within the 'kafka' namespace. This command helps confirm that the Kafka broker has been successfully installed and is running. ```bash kubectl get po -n kafka ``` -------------------------------- ### Python: Create and Consume Kafka Messages Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md This snippet demonstrates how to create a Kafka consumer client using the confluent_kafka library and continuously receive messages from a specified topic. It handles potential exceptions during message retrieval and prints each message. The code requires the confluent_kafka library to be installed. ```python from mqueue import CreateQueue kafkaQueue = CreateQueue(queueName='kerberos-storage-example-queue', broker='broker1.kerberos.io:9094,broker2.kerberos.io:9094,broker3.kerberos.io:9094', mechanism='PLAIN', security='SASL_PLAINTEXT', username= 'aaa', password='xxx') while True: try: messages = kafkaQueue.ReceiveMessages() for message in messages: print message print("next..") print("reading..") except Exception as e: print("error..") print(e) pass ``` ```python import json from confluent_kafka import Producer, Consumer def CreateQueue(queueName='', broker='', mechanism='', security='', username= '', password=''): return Kafka(queueName=queueName, broker=broker, mechanism=mechanism, security=security, username=username, password=password) class Kafka: def __init__(self, queueName='', broker='', mechanism='', security='', username= '', password=''): self.queueName = queueName kafkaC_settings = { 'bootstrap.servers': broker, "group.id": "mygroup", "session.timeout.ms": 10000, "queued.max.messages.kbytes": 10000, #10MB "auto.offset.reset": "earliest", "sasl.mechanisms": mechanism, #"PLAIN", "security.protocol": security, #"SASL_PLAINTEXT", "sasl.username": username, "sasl.password": password, } self.kafka_consumer = Consumer(kafkaC_settings) self.kafka_consumer.subscribe([self.queueName]) def ReceiveMessages(self): msg = self.kafka_consumer.poll(timeout=1.0) if msg is None: return [] return [json.loads(msg.value())] def Close(self): self.kafka_consumer.close() return True ``` -------------------------------- ### Install OpenEBS Storage Class for Kafka Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/kafka/README.md Applies the OpenEBS operator manifest to set up a storage class, which is a prerequisite for deploying Kafka within Kubernetes. This ensures persistent storage is available for the Kafka broker. ```bash kubectl apply -f https://openebs.github.io/charts/openebs-operator.yaml ``` -------------------------------- ### Modify Host File for DNS Resolution Source: https://github.com/kerberos-io/vault/blob/master/docker/README.md Adds entries to the host's /etc/hosts file to map DNS names to IP addresses. This allows accessing services like Kerberos Vault and Minio using custom domain names instead of IP addresses. ```bash x.x.x.x kerberos-vault-api.domain.tld kerberos-vault.domain.tld minio-console.domain.tld ``` -------------------------------- ### Deploy Kafka Broker using Helm Source: https://github.com/kerberos-io/vault/blob/master/kubernetes/kafka/README.md Clones the Kerberos Vault Kubernetes Kafka configuration, creates a dedicated namespace, and deploys the Kafka broker using Helm. This command assumes you have Helm and kubectl configured. ```bash git clone https://github.com/kerberos-io/vault && cd vault/kubernetes/kafka kubectl create namespace kafka helm install kafka bitnami/kafka -f values.yaml -n kafka ``` -------------------------------- ### Create MongoDB Index for Media Collection Source: https://github.com/kerberos-io/vault/blob/master/README.md This MongoDB command creates an index on the 'timestamp' field in the 'media' collection, sorted in descending order. This index is crucial for improving the performance of future queries on the media collection. ```javascript db.getCollection("media").createIndex({timestamp:-1}) ``` -------------------------------- ### Build Docker Image for Kafka Handler Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md Command to build a Docker image for the Kafka handler application. Requires a Dockerfile in the current directory. ```shell docker build -t kafka-handler . ``` -------------------------------- ### Fetch Recording from Kerberos Vault API Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md This endpoint allows you to retrieve binary files (recordings) from your defined Kerberos Vault provider (AWS, GCP, Azure, or Minio). It requires specific headers containing file identification and access credentials. ```APIDOC ## GET /api/storage/blob ### Description Retrieves a binary file (recording) from a specified Kerberos Vault provider using provided file name and access credentials. ### Method GET ### Endpoint `http(s)://your-kerberos-vault-domain.com/api/storage/blob` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Headers - **X-Kerberos-Storage-FileName** (string) - Required - The filename of the recording to retrieve. - **X-Kerberos-Storage-Provider** (string) - Required - The provider where the file was stored (e.g., AWS, GCP, Azure, Minio). - **X-Kerberos-Storage-AccessKey** (string) - Required - The AccessKey for the Kerberos Vault account. - **X-Kerberos-Storage-SecretAccessKey** (string) - Required - The SecretAccessKey for the Kerberos Vault account. ### Request Example ```python import requests fileName = message['payload']['key'] provider = message['source'] response = requests.get( 'http(s)://yourkerberostoragedomain.com/api/storage/blob', headers={ 'X-Kerberos-Storage-FileName': fileName, 'X-Kerberos-Storage-Provider': provider, 'X-Kerberos-Storage-AccessKey': 'YOUR_ACCESS_KEY', 'X-Kerberos-Storage-SecretAccessKey': 'YOUR_SECRET_ACCESS_KEY', }, ) if response.status_code == 200: fileContent = response.content with open('video.mp4', 'wb') as file: file.write(fileContent) else: print(f"Error retrieving file: {response.status_code} - {response.text}") ``` ### Response #### Success Response (200) - **fileContent** (binary) - The content of the requested recording file. #### Response Example (Binary content of the video file, saved to `video.mp4` in the example) ``` -------------------------------- ### Fetch Recording from Kerberos Vault API (Python) Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md This snippet demonstrates how to retrieve a recording from the Kerberos Vault API using the 'requests' library in Python. It extracts the filename and provider from a message, constructs the API request with necessary headers including access keys, and handles the response. If the request is successful (status code 200), the recording content is saved to a local 'video.mp4' file. Otherwise, an error message is printed. ```python import requests # Assuming 'message' is a dictionary containing 'payload' and 'source' # Example: message = {'payload': {'key': 'recording.mp4'}, 'source': 'aws'} fileName = message['payload']['key'] provider = message['source'] response = requests.get( 'http(s)://yourkerberostoragedomain.com/api/storage/blob', headers={ 'X-Kerberos-Storage-FileName': fileName, 'X-Kerberos-Storage-Provider': provider, 'X-Kerberos-Storage-AccessKey': 'xxx', 'X-Kerberos-Storage-SecretAccessKey': 'xxx', }, ) if response.status_code != 200: print("Something went wrong: " + response.content) else: fileContent = response.content with open('video.mp4', 'wb') as file: file.write(fileContent) print("Recording saved to video.mp4") ``` -------------------------------- ### Python: Process Video Frame and Calculate Histogram Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md This script snippet demonstrates how to capture the first frame from a video file named 'video.mp4', pass it to the `calculateHistogram` function, and print the resulting dominant RGB colors. It includes error handling for frame capture. ```python import cv2 # Assume calculateHistogram function is defined elsewhere or above # def calculateHistogram(img): # ... vidcap = cv2.VideoCapture('video.mp4') success, img = vidcap.read() histogram = [] if success: histogram = calculateHistogram(img) else: print("Something went wrong while capturing a frame from video.mp4") print(histogram) ``` -------------------------------- ### Deploy Kafka Handler to Kubernetes Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md Command to deploy the Kafka handler to a Kubernetes cluster using a provided YAML configuration file. Assumes Docker image is already built and accessible. ```shell kubectl apply -f kubernetes.yaml ``` -------------------------------- ### Bash: Execute Python Script for Color Detection Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md This command executes the Python script ('index.py' or similar) that performs video frame capture and color histogram calculation. ```bash python3 index.py ``` -------------------------------- ### Python: Calculate Color Histogram using OpenCV and Scikit-learn Source: https://github.com/kerberos-io/vault/blob/master/examples/kafka-handler/README.md This Python function, `calculateHistogram`, takes an image frame as input, converts it to RGB format, reshapes it for clustering, and uses scikit-learn's KMeans to find the dominant colors. It returns a list of the top 3 most common RGB color values. ```python import cv2 import numpy as np from sklearn.cluster import KMeans def calculateHistogram(img): img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) img = img.reshape((img.shape[0] * img.shape[1],3)) #represent as row*column,channel number clt = KMeans(n_clusters=3) clt.fit(img) numLabels = np.arange(0, len(np.unique(clt.labels_)) + 1) (hist, _) = np.histogram(clt.labels_, bins=numLabels) hist = hist.astype("float") hist /= hist.sum() rgbs = [] for cluster in clt.cluster_centers_: rgbs.append(list(map(int,cluster))) return rgbs ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.