Debug the Splunk Operator distroless image by attaching a sidecar container.
Since distroless images do not contain a shell, debugging requires a sidecar container that includes a shell and necessary utilities to inspect mapped volumes and files.
- Add a sidecar container to the
splunk-operator-controller-manager deployment. The sidecar container has a shell and basic debugging tools.
The following example deployment snippet adds a sidecar named sok-debug:
apiVersion: apps/v1
kind: Deployment
metadata:
name: splunk-operator-controller-manager
namespace: splunk-operator
spec:
replicas: 1
selector:
matchLabels:
control-plane: controller-manager
template:
metadata:
labels:
control-plane: controller-manager
spec:
containers:
- name: manager
image: splunk/splunk-operator:<version>-distroless
env:
- name: WATCH_NAMESPACE
value: ""
- name: RELATED_IMAGE_SPLUNK_ENTERPRISE
value: splunk/splunk:<version>
- name: SPLUNK_GENERAL_TERMS
value: ""
- name: sok-debug
image: ubuntu:20.04
command: ["/bin/bash", "-c", "tail -f /dev/null"]
volumeMounts:
- name: app-staging
mountPath: /opt/splunk/appframework/
volumes:
- name: app-staging
persistentVolumeClaim:
claimName: splunk-operator-app-download
- Access the sidecar container by running an exec command into it:
kubectl exec -it splunk-operator-pod-name -c sok-debug -- /bin/bash
- Navigate to the mounted volume to inspect files shared with the distroless container:
cd /opt/splunk/appframework/
ls -l
- Check logs by accessing the appropriate log files or using kubectl logs:
kubectl logs splunk-operator-pod-name -c manager
- After debugging, remove the sidecar container by editing the deployment and deleting the sidecar configuration, or redeploy the Splunk Operator without the sidecar.