|
| 1 | +# Test Environment for CACA Splunk App |
| 2 | +# This is a generic Kubernetes deployment for testing the CACA app |
| 3 | +# Customize the namespace, ingress, and other settings for your environment |
| 4 | +# |
| 5 | +# To retrieve the generated Splunk password after deployment: |
| 6 | +# kubectl get secret splunk-secret -n <your-namespace> -o jsonpath='{.data.password}' | base64 -d |
| 7 | + |
| 8 | +--- |
| 9 | +# Job to generate a random password for Splunk |
| 10 | +# This runs before the deployment and creates/updates the secret with a random password |
| 11 | +apiVersion: batch/v1 |
| 12 | +kind: Job |
| 13 | +metadata: |
| 14 | + name: splunk-password-generator |
| 15 | + namespace: default # Change to your namespace |
| 16 | +spec: |
| 17 | + ttlSecondsAfterFinished: 100 # Auto-cleanup after 100 seconds |
| 18 | + template: |
| 19 | + spec: |
| 20 | + serviceAccountName: default # Ensure the service account has permission to create secrets |
| 21 | + restartPolicy: Never |
| 22 | + containers: |
| 23 | + - name: generate-password |
| 24 | + image: bitnami/kubectl:latest |
| 25 | + command: |
| 26 | + - /bin/bash |
| 27 | + - -c |
| 28 | + - | |
| 29 | + # Generate a random 16-character password |
| 30 | + PASSWORD=$(cat /dev/urandom | tr -dc 'A-Za-z0-9!@#$%^&*' | head -c 16) |
| 31 | +
|
| 32 | + # Create or update the secret |
| 33 | + kubectl create secret generic splunk-secret \ |
| 34 | + --from-literal=password="$PASSWORD" \ |
| 35 | + --dry-run=client -o yaml | kubectl apply -f - |
| 36 | +
|
| 37 | + echo "Password secret created/updated successfully" |
| 38 | + echo "Retrieve with: kubectl get secret splunk-secret -o jsonpath='{.data.password}' | base64 -d" |
| 39 | +--- |
| 40 | +apiVersion: apps/v1 |
| 41 | +kind: Deployment |
| 42 | +metadata: |
| 43 | + name: splunk |
| 44 | + labels: |
| 45 | + app: splunk |
| 46 | + namespace: default # Change to your namespace |
| 47 | +spec: |
| 48 | + replicas: 1 |
| 49 | + strategy: |
| 50 | + type: RollingUpdate |
| 51 | + rollingUpdate: |
| 52 | + maxSurge: 1 |
| 53 | + maxUnavailable: 1 |
| 54 | + selector: |
| 55 | + matchLabels: |
| 56 | + app: splunk |
| 57 | + template: |
| 58 | + metadata: |
| 59 | + labels: |
| 60 | + app: splunk |
| 61 | + spec: |
| 62 | + hostname: splunk |
| 63 | + initContainers: |
| 64 | + - name: download-caca-app |
| 65 | + image: alpine/git:latest |
| 66 | + securityContext: |
| 67 | + runAsUser: 0 # Run as root to ensure write permissions |
| 68 | + env: |
| 69 | + # Change this to use a different branch (e.g., dev, feature/my-feature) |
| 70 | + - name: CACA_BRANCH |
| 71 | + value: "main" |
| 72 | + # Optionally override the GitHub repo URL |
| 73 | + # - name: CACA_REPO_URL |
| 74 | + # value: "https://github.com/yourusername/your-fork.git" |
| 75 | + command: |
| 76 | + - sh |
| 77 | + - -c |
| 78 | + - | |
| 79 | + set -e # Exit on any error |
| 80 | +
|
| 81 | + REPO_URL="${CACA_REPO_URL:-https://github.com/devinslick/splunk-content-monitoring-console.git}" |
| 82 | +
|
| 83 | + echo "=== CACA App Installation Starting ===" |
| 84 | + echo "Repository: ${REPO_URL}" |
| 85 | + echo "Branch: ${CACA_BRANCH}" |
| 86 | + echo "Target: /opt/splunk/etc/apps/caca" |
| 87 | +
|
| 88 | + echo "Checking volume mount..." |
| 89 | + ls -la /opt/splunk/etc/ || echo "WARNING: /opt/splunk/etc/ not accessible" |
| 90 | +
|
| 91 | + echo "Creating apps directory if needed..." |
| 92 | + mkdir -p /opt/splunk/etc/apps |
| 93 | +
|
| 94 | + echo "Removing old CACA app installation (if exists)..." |
| 95 | + rm -rf /opt/splunk/etc/apps/caca-content-activity-checking-application |
| 96 | + rm -rf /opt/splunk/etc/apps/caca |
| 97 | +
|
| 98 | + echo "Downloading CACA app from GitHub (branch: ${CACA_BRANCH})..." |
| 99 | + cd /tmp |
| 100 | + git clone --depth 1 --branch ${CACA_BRANCH} ${REPO_URL} |
| 101 | +
|
| 102 | + echo "Creating app directory..." |
| 103 | + mkdir -p /opt/splunk/etc/apps/caca |
| 104 | +
|
| 105 | + echo "Copying app files (excluding dev files)..." |
| 106 | + cd splunk-content-monitoring-console |
| 107 | +
|
| 108 | + # Copy all files except dev-specific ones |
| 109 | + find . -maxdepth 1 -mindepth 1 \ |
| 110 | + ! -name '.git*' \ |
| 111 | + ! -name 'local' \ |
| 112 | + ! -name 'devnotes' \ |
| 113 | + ! -name '.venv' \ |
| 114 | + ! -name '.pytest_cache' \ |
| 115 | + ! -name '.pre-commit-config.yaml' \ |
| 116 | + ! -name '.bandit.yml' \ |
| 117 | + ! -name 'CI-CD-SETUP.md' \ |
| 118 | + ! -name 'scripts' \ |
| 119 | + ! -name 'appinspect_report.json' \ |
| 120 | + ! -name '*.pyc' \ |
| 121 | + ! -name '__pycache__' \ |
| 122 | + -exec cp -r {} /opt/splunk/etc/apps/caca/ \; |
| 123 | +
|
| 124 | + echo "Setting permissions for Splunk user (41812)..." |
| 125 | + chown -R 41812:41812 /opt/splunk/etc/apps/caca |
| 126 | +
|
| 127 | + echo "=== CACA App Installation Complete ===" |
| 128 | + echo "Installed files:" |
| 129 | + ls -la /opt/splunk/etc/apps/caca/ |
| 130 | +
|
| 131 | + echo "SUCCESS: CACA app installed from ${REPO_URL} (branch: ${CACA_BRANCH})" |
| 132 | + volumeMounts: |
| 133 | + - mountPath: /opt/splunk/etc/apps |
| 134 | + name: splunk |
| 135 | + subPath: var/splunk-apps # Use a dedicated path in the PVC |
| 136 | + containers: |
| 137 | + - name: splunk |
| 138 | + image: splunk/splunk:latest |
| 139 | + imagePullPolicy: Always |
| 140 | + ports: |
| 141 | + - containerPort: 8000 |
| 142 | + name: http |
| 143 | + protocol: TCP |
| 144 | + - containerPort: 8088 |
| 145 | + name: hec |
| 146 | + protocol: TCP |
| 147 | + - containerPort: 9997 |
| 148 | + name: indexer |
| 149 | + protocol: TCP |
| 150 | + volumeMounts: |
| 151 | + - mountPath: /opt/splunk/var |
| 152 | + name: splunk |
| 153 | + subPath: var |
| 154 | + - mountPath: /opt/splunk/etc/apps |
| 155 | + name: splunk |
| 156 | + subPath: var/splunk-apps # Share same PVC, different subPath |
| 157 | + env: |
| 158 | + - name: TZ |
| 159 | + value: 'America/Chicago' # Change to your timezone |
| 160 | + - name: SPLUNK_GENERAL_TERMS |
| 161 | + value: '--accept-sgt-current-at-splunk-com' |
| 162 | + - name: SPLUNK_START_ARGS |
| 163 | + value: '--accept-license --no-prompt --answer-yes' |
| 164 | + - name: SPLUNK_HTTP_PORT |
| 165 | + value: "8000" |
| 166 | + - name: SPLUNK_HEC_PORT |
| 167 | + value: "8088" |
| 168 | + - name: SPLUNK_PASSWORD |
| 169 | + valueFrom: |
| 170 | + secretKeyRef: |
| 171 | + name: splunk-secret |
| 172 | + key: password |
| 173 | + livenessProbe: |
| 174 | + httpGet: |
| 175 | + path: / |
| 176 | + port: 8000 |
| 177 | + initialDelaySeconds: 60 |
| 178 | + periodSeconds: 30 |
| 179 | + volumes: |
| 180 | + - name: splunk |
| 181 | + persistentVolumeClaim: |
| 182 | + claimName: splunk # Change to your PVC name |
| 183 | +--- |
| 184 | +apiVersion: v1 |
| 185 | +kind: Service |
| 186 | +metadata: |
| 187 | + name: splunk-http |
| 188 | + namespace: default # Change to your namespace |
| 189 | + labels: |
| 190 | + app: splunk |
| 191 | +spec: |
| 192 | + ports: |
| 193 | + - name: http |
| 194 | + port: 8000 |
| 195 | + type: ClusterIP |
| 196 | + selector: |
| 197 | + app: splunk |
| 198 | +--- |
| 199 | +apiVersion: v1 |
| 200 | +kind: Service |
| 201 | +metadata: |
| 202 | + name: splunk-hec |
| 203 | + namespace: default # Change to your namespace |
| 204 | + labels: |
| 205 | + app: splunk |
| 206 | +spec: |
| 207 | + ports: |
| 208 | + - name: hec |
| 209 | + port: 8088 |
| 210 | + type: ClusterIP |
| 211 | + selector: |
| 212 | + app: splunk |
| 213 | +--- |
| 214 | +apiVersion: v1 |
| 215 | +kind: Service |
| 216 | +metadata: |
| 217 | + name: splunk-indexer |
| 218 | + namespace: default # Change to your namespace |
| 219 | + labels: |
| 220 | + app: splunk |
| 221 | +spec: |
| 222 | + ports: |
| 223 | + - name: indexer |
| 224 | + port: 9997 |
| 225 | + type: ClusterIP |
| 226 | + selector: |
| 227 | + app: splunk |
0 commit comments