Skip to content

Instantly share code, notes, and snippets.

@icicimov
Created June 17, 2019 05:37
Show Gist options
  • Save icicimov/edab817e4cae732b1c1be014e2035a4f to your computer and use it in GitHub Desktop.
Save icicimov/edab817e4cae732b1c1be014e2035a4f to your computer and use it in GitHub Desktop.
Kubernetes local core dns cache
# Run kubelet with "--cluster-dns 169.254.20.10"
# In Kops we need to update the cluster spec:
#spec:
# kubelet:
# clusterDNS: 169.254.20.10
#
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: node-local-dns
namespace: kube-system
labels:
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
---
apiVersion: v1
kind: ConfigMap
metadata:
name: node-local-dns
namespace: kube-system
labels:
addonmanager.kubernetes.io/mode: EnsureExists
data:
Corefile: |
cluster.local:53 {
errors
bind 169.254.20.10
forward . 100.64.0.10 {
force_tcp
}
cache {
success 9984 30
denial 9984 5
}
reload
loop
prometheus :9253
health 169.254.20.10:8080
}
in-addr.arpa:53 {
errors
bind 169.254.20.10
forward . 100.64.0.10 {
force_tcp
}
cache 30
reload
loop
prometheus :9253
}
ip6.arpa:53 {
errors
bind 169.254.20.10
forward . 100.64.0.10 {
force_tcp
}
cache 30
reload
loop
prometheus :9253
}
.:53 {
errors
bind 169.254.20.10
forward . /etc/resolv.conf
cache 30
reload
prometheus :9253
}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-local-dns
namespace: kube-system
labels:
k8s-app: node-local-dns
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
spec:
updateStrategy:
rollingUpdate:
maxUnavailable: 10%
selector:
matchLabels:
k8s-app: node-local-dns
template:
metadata:
labels:
k8s-app: node-local-dns
spec:
priorityClassName: system-node-critical
serviceAccountName: node-local-dns
hostNetwork: true
dnsPolicy: Default # Don't use cluster DNS.
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
- key: node-role.kubernetes.io/master
operator: "Exists"
effect: NoSchedule
containers:
- name: node-cache
image: k8s.gcr.io/k8s-dns-node-cache:1.15.0
resources:
limits:
memory: 30Mi
requests:
cpu: 25m
memory: 5Mi
args: [ "-localip", "169.254.20.10", "-conf", "/etc/coredns/Corefile" ]
securityContext:
privileged: true
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 9253
name: metrics
protocol: TCP
- containerPort: 6060
name: pprof
protocol: TCP
livenessProbe:
httpGet:
host: 169.254.20.10
path: /health
port: 8080
initialDelaySeconds: 60
timeoutSeconds: 5
volumeMounts:
- mountPath: /run/xtables.lock
name: xtables-lock
readOnly: false
- name: config-volume
mountPath: /etc/coredns
volumes:
- name: xtables-lock
hostPath:
path: /run/xtables.lock
type: FileOrCreate
- name: config-volume
configMap:
name: node-local-dns
items:
- key: Corefile
path: Corefile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment