···11+---
22+title: "Rebuilding the homelab: Fixing longhorn was annoyingly easy"
33+desc: "lol oops"
44+date: 2024-05-09
55+tags:
66+ - homelab
77+ - k8s
88+ - longhorn
99+---
1010+1111+This is a followup to [my last post](../04/), where I was trying to get Longhorn working on my cluster. Turns out the problem was really stupid and I need to explain what's going on so you can properly commiserate.
1212+1313+Talos Linux sets a default security policy that blocks the Longhorn manager from running. This is because the Longhorn manager runs as root and Talos Linux is paranoid about security. In order to get Longhorn running, I had to add the following annotations to the Longhorn namespace:
1414+1515+```yaml
1616+apiVersion: v1
1717+kind: Namespace
1818+metadata:
1919+ name: longhorn-system
2020+ labels:
2121+ pod-security.kubernetes.io/enforce: privileged
2222+ pod-security.kubernetes.io/enforce-version: latest
2323+ pod-security.kubernetes.io/audit: privileged
2424+ pod-security.kubernetes.io/audit-version: latest
2525+ pod-security.kubernetes.io/warn: privileged
2626+ pod-security.kubernetes.io/warn-version: latest
2727+```
2828+2929+Then you can create a PersistentVolumeClaim and attach it to a pod:
3030+3131+```yaml
3232+apiVersion: v1
3333+kind: PersistentVolumeClaim
3434+metadata:
3535+ name: longhorn-volv-pvc
3636+ namespace: default
3737+spec:
3838+ accessModes:
3939+ - ReadWriteOnce
4040+ storageClassName: longhorn
4141+ resources:
4242+ requests:
4343+ storage: 2Gi
4444+---
4545+apiVersion: v1
4646+kind: Pod
4747+metadata:
4848+ name: volume-test
4949+ namespace: default
5050+spec:
5151+ restartPolicy: Always
5252+ containers:
5353+ - name: volume-test
5454+ image: nginx:stable-alpine
5555+ imagePullPolicy: IfNotPresent
5656+ livenessProbe:
5757+ exec:
5858+ command:
5959+ - ls
6060+ - /data/lost+found
6161+ initialDelaySeconds: 5
6262+ periodSeconds: 5
6363+ volumeMounts:
6464+ - name: volv
6565+ mountPath: /data
6666+ ports:
6767+ - containerPort: 80
6868+ volumes:
6969+ - name: volv
7070+ persistentVolumeClaim:
7171+ claimName: longhorn-volv-pvc
7272+```
7373+7474+<Conv name="Cadey" mood="facepalm">
7575+ I feel so dumb right now. It was just a security policy mismatch.
7676+</Conv>