Skip to content

Instantly share code, notes, and snippets.

@3deep5me
Last active September 2, 2025 20:20
Show Gist options
  • Save 3deep5me/37269203a0280b83a54eba80f0314156 to your computer and use it in GitHub Desktop.
Save 3deep5me/37269203a0280b83a54eba80f0314156 to your computer and use it in GitHub Desktop.
Try to setup multiple kind clusters with also an external interface
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: node-ip-reporter-role
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch", "patch", "update"]
- apiGroups: [""]
resources: ["nodes/status"]
verbs: ["patch", "update", "get"]
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: node-ip-reporter-binding
subjects:
- kind: ServiceAccount
name: node-ip-reporter
namespace: default
roleRef:
kind: ClusterRole
name: node-ip-reporter-role
apiGroup: rbac.authorization.k8s.io
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-ip-reporter
namespace: default
spec:
selector:
matchLabels:
name: node-ip-reporter
template:
metadata:
labels:
name: node-ip-reporter
spec:
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
- key: node.cloudprovider.kubernetes.io/uninitialized
value: "true"
hostNetwork: true
serviceAccountName: node-ip-reporter
initContainers:
- name: get-node-ips
image: busybox
command: ["sh", "-c"]
args:
- |
# Extract internal IP (assuming it's in the 172.18.0.x range)
INTERNAL_IP=$(ip addr | grep '172.18.0' | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
# Extract external IP (assuming it's in the 192.168.x.x range)
EXTERNAL_IP=$(ip addr | grep '192.168' | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
# Write the IPs to the shared volume
echo $INTERNAL_IP > /node-ips/internal-ip
echo $EXTERNAL_IP > /node-ips/external-ip
volumeMounts:
- name: node-ips
mountPath: /node-ips
containers:
- name: report-node-ips
image: bitnami/kubectl:latest
#command: ["/bin/sh", "-c"]
command: ["sh", "-c"]
args:
- |
INTERNAL_IP=$(cat /node-ips/internal-ip)
EXTERNAL_IP=$(cat /node-ips/external-ip)
echo "$NODE_NAME"
echo "INTERNAL_IP: $INTERNAL_IP"
echo "EXTERNAL_IP: $EXTERNAL_IP"
# Patch the node status with the internal and external IPs
kubectl patch node $NODE_NAME --subresource status --type='json' -p '[{"op":"add","path":"/status/addresses/-", "value": {"type": "InternalIP", "address": "'"$INTERNAL_IP"'"} }]'
kubectl patch node $NODE_NAME --subresource status --type='json' -p '[{"op":"add","path":"/status/addresses/-", "value": {"type": "ExternalIP", "address": "'"$EXTERNAL_IP"'"} }]'
# unTaint the node
kubectl taint node $NODE_NAME node.cloudprovider.kubernetes.io/uninitialized-
# Keep the container running
sleep infinity
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: node-ips
mountPath: /node-ips
volumes:
- name: node-ips
emptyDir: {}
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
cloud-provider: external
- |
kind: JoinConfiguration
nodeRegistration:
kubeletExtraArgs:
cloud-provider: external
- role: worker
kubeadmConfigPatches:
- |
kind: JoinConfiguration
nodeRegistration:
kubeletExtraArgs:
cloud-provider: external
name: kind01
topology:
kinds:
nokia_srlinux:
image: ghcr.io/nokia/srlinux:23.10.1
nodes:
srl01:
kind: nokia_srlinux
k01:
kind: k8s-kind
startup-config: k01-config.yaml
k02:
kind: k8s-kind
startup-config: k01-config.yaml
k01-control-plane:
kind: ext-container
exec:
- "ip addr add dev eth1 192.168.10.1/24"
k01-worker:
kind: ext-container
exec:
- "ip addr add dev eth1 192.168.11.1/24"
k02-control-plane:
kind: ext-container
exec:
- "ip addr add dev eth1 192.168.20.1/24"
k02-worker:
kind: ext-container
exec:
- "ip addr add dev eth1 192.168.21.1/24"
links:
- endpoints: ["srl01:e1-1", "k01-control-plane:eth1"]
- endpoints: ["srl01:e1-2", "k01-worker:eth1"]
- endpoints: ["srl01:e1-3", "k02-control-plane:eth1"]
- endpoints: ["srl01:e1-4", "k02-worker:eth1"]
apiVersion: v1
kind: ServiceAccount
metadata:
name: node-ip-reporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment