configmap配置
[root@kubeadm-master dns]# cat dnsmasq-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: dnsmasq-configmap
data:
dnsmasq.conf: |
resolv-file=/etc/dnsmasq.d/resolv.dnsmasq
addn-hosts=/etc/dnsmasq.d/dnsmasqhosts
## 下面一句是把ning.com指给192.168.100.110,就是ingress-server的ip
address=/ning.com/192.168.100.110
dnsmasqhosts: |
192.168.100.110 *.ning.com
resolv.dnsmasq: |
nameserver 114.114.114.114
nameserver 8.8.8.8
DaemonSet配置
[root@kubeadm-master dns]# cat dnsmasq-daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: dnsmasq
labels:
app: dnsmasq
spec:
selector:
matchLabels:
app: dnsmasq
template:
metadata:
labels:
app: dnsmasq
spec:
nodeSelector:
node-role.kubernetes.io/master: ""
hostNetwork: true
tolerations:
- effect: NoSchedule
operator: Exists
containers:
- name: dnsmasq
image: andyshinn/dnsmasq:latest
imagePullPolicy: IfNotPresent
securityContext:
capabilities:
add:
- NET_ADMIN
readinessProbe:
tcpSocket:
port: 53
initialDelaySeconds: 30
timeoutSeconds: 1
livenessProbe:
tcpSocket:
port: 53
initialDelaySeconds: 30
timeoutSeconds: 1
ports:
- containerPort: 53
protocol: UDP
name: dns-udp
- containerPort: 53
protocol: TCP
name: dns-tcp
volumeMounts:
- name: config-volume
mountPath: /etc/dnsmasq.d/
volumes:
- name: config-volume
configMap:
name: dnsmasq-configmap
items:
- key: dnsmasqhosts
path: dnsmasqhosts
- key: resolv.dnsmasq
path: resolv.dnsmasq
- key: dnsmasq.conf
path: dnsmasq.conf
---
apiVersion: v1
kind: Service
metadata:
name: dnsmasq
labels:
app: dnsmasq
spec:
ports:
- port: 53
targetPort: 53
protocol: TCP
name: dns-tcp
- port: 53
targetPort: 53
protocol: UDP
name: dns-udp
selector:
app: dnsmasq
kubectl apply -f dnsmasq-cm.yaml -n kube-system
kubectl apply -f dnsmasq-daemonset.yaml -n kube-system
将客户端的dns指向dnsmasq的ip 及完成