Kubernetes
Before you start, prepare a namespace and register an agent.
This manifest runs a Deployment whose pods each hold the agent, CoreDNS and
an init container that writes the starter Corefile, and a Service for port
53. Each replica fetches the configuration itself, so you can scale it freely.
Create the namespace and the credential secret first:
kubectl create namespace valgrid-dns
kubectl -n valgrid-dns create secret generic valgrid-agent-token \
--from-file=token=./agent-token
Save the manifest as valgrid-dns.yaml, set VALGRID_NAMESPACE_ID and the
image tag, and apply it with kubectl apply -f valgrid-dns.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
name: valgrid-agent
namespace: valgrid-dns
data:
VALGRID_API_URL: https://api.valgrid.io
VALGRID_NAMESPACE_ID: "<namespace_id>"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: valgrid-dns
namespace: valgrid-dns
spec:
replicas: 2
selector:
matchLabels:
app.kubernetes.io/name: valgrid-dns
template:
metadata:
labels:
app.kubernetes.io/name: valgrid-dns
spec:
securityContext:
runAsNonRoot: true
runAsUser: 65532
runAsGroup: 65532
fsGroup: 65532
seccompProfile:
type: RuntimeDefault
initContainers:
- name: agent-init
image: ghcr.io/valgrid-dns/valgrid-agent:<version>
args: ["-init"]
env:
- name: VALGRID_COREFILE
value: /var/lib/valgrid/Corefile
volumeMounts:
- name: zones
mountPath: /var/lib/valgrid
securityContext: &restricted
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
containers:
- name: agent
image: ghcr.io/valgrid-dns/valgrid-agent:<version>
envFrom:
- configMapRef:
name: valgrid-agent
env:
- name: VALGRID_AGENT_TOKEN_FILE
value: /run/secrets/valgrid/token
volumeMounts:
- name: zones
mountPath: /var/lib/valgrid
- name: token
mountPath: /run/secrets/valgrid
readOnly: true
securityContext: *restricted
resources:
requests: {cpu: 10m, memory: 32Mi}
limits: {memory: 128Mi}
- name: coredns
image: coredns/coredns:1.15.0
args: ["-conf", "/var/lib/valgrid/Corefile"]
ports:
- {name: dns, containerPort: 53, protocol: UDP}
- {name: dns-tcp, containerPort: 53, protocol: TCP}
livenessProbe:
httpGet: {path: /health, port: 8080}
readinessProbe:
httpGet: {path: /ready, port: 8181}
volumeMounts:
- name: zones
mountPath: /var/lib/valgrid
readOnly: true
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: [ALL]
add: [NET_BIND_SERVICE]
resources:
requests: {cpu: 50m, memory: 64Mi}
limits: {memory: 256Mi}
volumes:
- name: zones
emptyDir: {}
- name: token
secret:
secretName: valgrid-agent-token
---
apiVersion: v1
kind: Service
metadata:
name: valgrid-dns
namespace: valgrid-dns
spec:
selector:
app.kubernetes.io/name: valgrid-dns
ports:
- {name: dns, port: 53, targetPort: dns, protocol: UDP}
- {name: dns-tcp, port: 53, targetPort: dns-tcp, protocol: TCP}
The replicas share one agent credential. Register a separate agent and
Deployment per site if you want to revoke sites independently.
Reach the DNS servers from outside the cluster
The Service above is a ClusterIP service, reachable only inside the
cluster. To serve clients and resolvers elsewhere in your network, give it a
stable address your network can reach, for example with type: LoadBalancer
and your load balancer's annotation for an internal address, and use that
address in your resolver configuration.
To use the zones from pods in the same cluster, see Kubernetes cluster DNS.
Next steps
Verify the DNS server, then point clients at it. See CoreDNS for the starter Corefile and how to change it.