- Shell 88.9%
- Dockerfile 11.1%
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| Dockerfile | ||
| Readme.md | ||
| renovate.json | ||
| samba-kinit.sh | ||
| start.sh | ||
samba-dc-docker
Alpine-based Samba 4 Active Directory Domain Controller image for Kubernetes.
Features
- Full AD DC (Kerberos, LDAP, DNS, SYSVOL, GPO)
- Windows Server 2016 functional level support
- Samba's internal DNS backend
- Dual-stack IPv4/IPv6
- Designed for Calico BGP mode (direct pod IP, no NAT)
- Auto-bootstraps Kerberos machine account ticket on start
- Single PVC for all state (
/var/lib/samba)
Environment Variables
| Variable | Required | Description |
|---|---|---|
SAMBA_REALM |
Yes | Kerberos realm in uppercase, e.g. AD.JONASLED.DE |
SAMBA_DC_IP |
Yes | The dedicated IP assigned to this pod |
SAMBA_DNS_FORWARDER |
No | Upstream DNS forwarder (default: 8.8.8.8) |
First-Time Setup (Joining an Existing Domain)
On first start with an empty PVC, the container will print the join command and sleep. Exec in and run it:
kubectl exec -it -n samba <pod-name> -- bash
samba-tool domain join AD.EXAMPLE.COM DC \
--dns-backend=SAMBA_INTERNAL \
--username=Administrator \
--server=<EXISTING_DC_IP> \
--option='netbios name = SAMBA-DC01' \
--option='ad dc functional level = 2016' \
--option='dns forwarder = <DNS_FORWARDER_IP>' \
--targetdir=/var/lib/samba
After the join completes, restart the pod — it will detect sam.ldb and start Samba automatically.
Note:
--option='ad dc functional level = 2016'is required when joining a Windows Server 2016 functional level domain. Without it the join will fail withWERR_DS_INCOMPATIBLE_VERSION.
Networking Requirements
This image is designed for Calico BGP mode without NAT. Each DC pod must have a dedicated routable IP assigned via Calico IPAM annotations.
Calico IPPool
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: samba-dc-v4
spec:
cidr: "10.x.x.x/30"
ipipMode: Never
vxlanMode: Never
natOutgoing: false
assignmentMode: Manual
nodeSelector: "!all()"
---
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: samba-dc-v6
spec:
cidr: "2a0e:xxxx:xxxx:x::/64"
ipipMode: Never
vxlanMode: Never
natOutgoing: false
assignmentMode: Manual
nodeSelector: "!all()"
CoreDNS Integration
Forward your AD domain to the Samba DC in CoreDNS:
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
forward . /etc/resolv.conf
cache 30
loop
reload
loadbalance
}
ad.example.com:53 {
errors
forward . <SAMBA_DC_IP>
cache 30
}
FSMO Roles
After joining and verifying replication, transfer all FSMO roles to the Samba DC:
# Graceful transfer (source DC still online)
samba-tool fsmo transfer --role=all -Uadministrator
# Force seize (source DC offline or deleted)
samba-tool fsmo seize --role=all --force -Uadministrator
# Verify
samba-tool fsmo show
SYSVOL Sync
Samba does not support DFSR. Copy SYSVOL from the source DC manually:
# Create credentials file
cat > /tmp/smb-creds << 'EOF'
username=administrator
password=YourPassword
domain=YOURDOMAIN
EOF
chmod 600 /tmp/smb-creds
# Pull SYSVOL content
cd /var/lib/samba/state/sysvol
smbclient //SOURCE-DC.ad.example.com/SYSVOL \
-A /tmp/smb-creds \
-m SMB3 \
-c 'recurse on; prompt off; mget *'
# Fix permissions
mkdir -p /var/lib/samba/state/sysvol/ad.example.com/scripts
samba-tool ntacl sysvolreset
samba-tool ntacl sysvolcheck
Decommissioning the Old DC
# On Windows DC
Uninstall-ADDSDomainController `
-LastDomainControllerInDomain:$false `
-RemoveApplicationPartitions:$true `
-Confirm:$false
After reboot, clean up metadata from Samba:
samba-tool domain demote --remove-other-dead-server=OLD-DC -Uadministrator
samba-tool domain dclist
Example Kubernetes Deployment
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: samba-dc02
namespace: samba
spec:
replicas: 1
updateStrategy:
type: RollingUpdate
selector:
matchLabels:
app: samba-dc02
template:
metadata:
annotations:
cni.projectcalico.org/ipAddrs: '["10.3.9.82", "2a0e:97c0:b50:3::2"]'
labels:
app: samba-dc02
spec:
hostname: samba-dc02
dnsPolicy: "None"
dnsConfig:
nameservers:
- 10.3.9.82
searches:
- ad.jonasled.de
options:
- name: ndots
value: "5"
hostAliases:
- ip: "10.3.9.82"
hostnames:
- "samba-dc02.ad.jonasled.de"
- "samba-dc02"
- ip: "2a0e:97c0:b50:3::2"
hostnames:
- "samba-dc02.ad.jonasled.de"
- "samba-dc02"
containers:
- name: samba-dc02
image: jonasled.dev/jonasled/samba-dc-docker:latest@sha256:2cd31f40baa66128af3e845cad603c091bfec39e1737a0b00458b553c378a0ef
securityContext:
privileged: true
env:
- name: SAMBA_REALM
value: "AD.JONASLED.DE"
- name: SAMBA_DC_IP
value: "10.3.9.82"
- name: SAMBA_DNS_FORWARDER
value: "10.3.15.15"
volumeMounts:
- name: samba-data
mountPath: /var/lib/samba
ports:
- containerPort: 53
protocol: TCP
- containerPort: 53
protocol: UDP
- containerPort: 88
protocol: TCP
- containerPort: 88
protocol: UDP
- containerPort: 135
protocol: TCP
- containerPort: 389
protocol: TCP
- containerPort: 445
protocol: TCP
- containerPort: 464
protocol: TCP
- containerPort: 464
protocol: UDP
- containerPort: 636
protocol: TCP
- containerPort: 3268
protocol: TCP
- containerPort: 3269
protocol: TCP
- containerPort: 49153
protocol: TCP
volumes:
- name: samba-data
persistentVolumeClaim:
claimName: samba-dc02-data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: samba-dc02-data
namespace: samba
spec:
accessModes: [ReadWriteOnce]
resources:
requests:
storage: 20Gi
Note on
dnsPolicy: None+ self-referencing nameserver: The pod's own IP is used as the nameserver so Samba resolves AD records via its own internal DNS. This is intentional — the pod must be running before DNS works, so on first start (when sleeping for domain join) name resolution for AD records will not work until Samba is actually started.
Ports
| Port | Protocol | Service |
|---|---|---|
| 53 | TCP/UDP | DNS |
| 88 | TCP/UDP | Kerberos |
| 135 | TCP | RPC Endpoint Mapper |
| 389 | TCP | LDAP |
| 445 | TCP | SMB (SYSVOL/NETLOGON) |
| 464 | TCP/UDP | Kerberos password change |
| 636 | TCP | LDAPS |
| 3268 | TCP | Global Catalog |
| 3269 | TCP | Global Catalog SSL |
| 49153 | TCP | Dynamic RPC (DRS replication) |
Backup
# Online backup
samba-tool domain backup online \
--targetdir=/var/lib/samba/backups \
--server=samba-dc01.ad.example.com \
-Uadministrator
# Snapshot the PVC via your storage provider (e.g. Ceph RBD snapshot)