This script detects and resolves IP address conflicts in Kubernetes clusters using the Whereabouts CNI plugin.
It identifies duplicate IP allocations in both pod annotations and Whereabouts CRDs, then resolves them using a deterministic priority system.
Telco Cloud Automation 3.2.0.1
TKG versions prior to 2.5.4
Whereabouts v0.5.4 has a known issue that results in this behavior.
This script detects and resolves IP address conflicts in Kubernetes clusters using the Whereabouts CNI plugin. It identifies duplicate IP allocations in both pod annotations and Whereabouts CRDs, then resolves them using a deterministic priority system.
Download the script attached to this KB and copy it to the Kubernetes cluster's control plane.
kubectl` - Must be configured with access to your Kubernetes clusterjq` - JSON processor (version 1.5+)base64` - Base64 encoding/decoding (usually pre-installed)bash` - Version 4.0+ (for associative arrays)timeout` - Command timeout utility (script has fallback if not available)
./detect_IP_conflict_v1.0.2.sh [MODE]
**Read-only mode** - Scans and reports conflicts without making changes.
./detect_IP_conflict_v1.0.2.sh A
# or simply (A is default)./detect_IP_conflict_v1.0.2.sh
**What it does:**
**Use when:**
**Fixes CRD issues** - Removes stale and duplicate entries from Whereabouts CRDs.
./detect_IP_conflict_v1.0.2.sh B
**What it does:**
**Use when:**
**Full cleanup** - Most aggressive mode, fixes CRDs and deletes duplicate pods.
./detect_IP_conflict_v1.0.2.sh C
**What it does:**
--grace-period=0 --force` for immediate deletion**Use when:**
./detect_IP_conflict_v1.0.2.sh A
**Output example:**=== Whereabouts IP Duplicate Detector(v1.0.2) ===Mode: A (A=Detect, B=Fix CRD, C=Fix+Delete Pods)Priority: Pods with CRD entries in Whereabouts are kept over pods without CRD entries
Scanning pods for network-status IPs......
Duplicate pod annotation IP detected: 10.0.1.5 Found 2 pods with this IP: - default/app-pod-1 (created: 2024-01-01T10:00:00Z) - default/app-pod-2 (created: 2024-01-01T11:00:00Z) default/app-pod-1: CRD entry = true default/app-pod-2: CRD entry = false → Will DELETE: default/app-pod-2 (no CRD entry) → Will KEEP: default/app-pod-1 (has CRD entry in Whereabouts)
./detect_IP_conflict_v1.0.2.sh B
./detect_IP_conflict_v1.0.2.sh CKUBECTL_TIMEOUT=120 ./detect_IP_conflict_v1.0.2.sh A
Duplicate pod annotation IP detected: <IP> Found N pods with this IP: - <namespace>/<pod> (created: <timestamp>) - <namespace>/<pod> (created: <timestamp>) <namespace>/<pod>: CRD entry = true/false <namespace>/<pod>: CRD entry = true/false → Will DELETE: <namespace>/<pod> (<reason>) → Will KEEP: <namespace>/<pod> (<reason>)
**Reasons for deletion:**
Processing CRD: <namespace>/<crd-name>→ Removing stale allocation <namespace>/<pod>→ Removing duplicate CRD allocation <namespace>/<pod> for IP <IP>✔ Updated <namespace>/<crd-name>
Deleting pod <namespace>/<pod> (duplicate IP <IP>)✓ Successfully deleted <namespace>/<pod>
Script Hangs:
KUBECTL_TIMEOUT=5 ./detect_IP_conflict_v1.0.2.sh A
kubectl connectivitykubectl get pods -A"Command not found" Errors:
command -v kubectl
command -v jq
command -v base64
Permission Denied:
kubectl get pods -Akubectl auth can-i delete pods
No Conflicts Detected:
Unexpected Pod Deletions:
./detect_IP_conflict_v1.0.2.sh A
./detect_IP_conflict_v1.0.2.sh B ./detect_IP_conflict_v1.0.2.sh C
KUBECTL_TIMEOUT=60 ./detect_IP_conflict_v1.0.2.sh A
./detect_IP_conflict_v1.0.2.sh A./detect_IP_conflict_v1.0.2.sh B
./detect_IP_conflict_v1.0.2.sh A
./detect_IP_conflict_v1.0.2.sh CSets the timeout for kubectl commands in seconds. Default: 30 seconds.
./detect_IP_conflict_v1.0.2.sh A
KUBECTL_TIMEOUT=60 ./detect_IP_conflict_v1.0.2.sh A
KUBECTL_TIMEOUT=5 ./detect_IP_conflict_v1.0.2.sh A**When to adjust:**
The script uses deterministic priority to decide which pod to keep when multiple pods claim the same IP:
For issues or questions: