Skip to content

Commit b5d8d41

Browse files
Fix NetBox NGINX deployment for IPv4-only environments (#333)
* Mount IPv4-only nginx-unit config in vCluster to avoid IPv6 socket error Added nginx-unit.json as a ConfigMap and patched the NetBox deployment to mount it, bypassing IPv6 listener issues ([::]:8080) inside vClusters where IPv6 is not enabled. --------- Co-authored-by: Pablo Garcia Miranda <pablo.garciamiranda@swisscom.com>
1 parent 63d4567 commit b5d8d41

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

kind/deploy-netbox.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ VERSION=$2
2020
# The specified namespace will be used for both the NetBox deployment and the vCluster creation
2121
NAMESPACE=$3
2222

23+
# Force IPv4-only config for environments lacking IPv6
24+
FORCE_NETBOX_NGINX_IPV4="${FORCE_NETBOX_NGINX_IPV4:-false}"
25+
2326
# Treat the optional fourth argument "--vcluster" as a boolean flag
2427
IS_VCLUSTER=false
2528
if [[ "${4:-}" == "--vcluster" ]]; then
@@ -201,6 +204,35 @@ ${HELM} upgrade --install netbox ${NETBOX_HELM_CHART} \
201204
--set resources.limits.memory="2Gi" \
202205
$REGISTRY_ARG
203206

207+
if [[ "$FORCE_NETBOX_NGINX_IPV4" == "true" ]]; then
208+
echo "Creating nginx-unit ConfigMap and patching deployment"
209+
210+
${KUBECTL} apply -f "$SCRIPT_DIR/nginx-unit-config.yaml" -n "$NAMESPACE"
211+
212+
${KUBECTL} patch deployment netbox -n "$NAMESPACE" --type=json -p='[
213+
{
214+
"op": "add",
215+
"path": "/spec/template/spec/volumes/-",
216+
"value": {
217+
"name": "unit-config",
218+
"configMap": {
219+
"name": "nginx-unit-config"
220+
}
221+
}
222+
},
223+
{
224+
"op": "add",
225+
"path": "/spec/template/spec/containers/0/volumeMounts/-",
226+
"value": {
227+
"mountPath": "/etc/unit/nginx-unit.json",
228+
"subPath": "nginx-unit.json",
229+
"name": "unit-config"
230+
}
231+
}
232+
]'
233+
234+
fi
235+
204236
${KUBECTL} rollout status --namespace="${NAMESPACE}" deployment netbox
205237

206238
# Create ConfigMap for the Python script

kind/nginx-unit-config.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: nginx-unit-config
5+
data:
6+
nginx-unit.json: |
7+
{
8+
"listeners": {
9+
"0.0.0.0:8080": { "pass": "routes/main" },
10+
"0.0.0.0:8081": { "pass": "routes/status" }
11+
},
12+
"routes": {
13+
"main": [
14+
{
15+
"match": { "uri": "/static/*" },
16+
"action": { "share": "/opt/netbox/netbox${uri}" }
17+
},
18+
{
19+
"action": { "pass": "applications/netbox" }
20+
}
21+
],
22+
"status": [
23+
{
24+
"match": { "uri": "/status/*" },
25+
"action": { "proxy": "http://unix:/opt/unit/unit.sock" }
26+
}
27+
]
28+
},
29+
"applications": {
30+
"netbox": {
31+
"type": "python 3",
32+
"path": "/opt/netbox/netbox/",
33+
"module": "netbox.wsgi",
34+
"home": "/opt/netbox/venv",
35+
"processes": {
36+
"max": 4,
37+
"spare": 1,
38+
"idle_timeout": 120
39+
}
40+
}
41+
},
42+
"access_log": "/dev/stdout"
43+
}

0 commit comments

Comments
 (0)