k8s搭建自定义dns

1configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: dnsmasq-configmap
data:
  dnsmasq.conf: |
    resolv-file=/etc/dnsmasq.d/resolv.dnsmasq
    addn-hosts=/etc/dnsmasq.d/dnsmasqhosts
  dnsmasqhosts: |
    192.168.1.225 gw.api.taobao.com
  resolv.dnsmasq: |
    nameserver 114.114.114.114
    nameserver 8.8.8.8

2.deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dnsmasq
  labels:
    app: dnsmasq
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: dnsmasq
    spec:
      nodeSelector:
        deploy: app
      containers:
      - name: dnsmasq
        image: andyshinn/dnsmasq:latest
        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

创建上面两个yaml配置文件。

然后创建下面configmap,使自定义dns接入到原来kubedns系统中

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-dns
  namespace: kube-system
data:
  stubDomains: |
    {"taobao.com": ["10.104.205.80"]}
  upstreamNameservers: |
    ["8.8.8.8", "8.8.4.4"]


你可能感兴趣的:(kubernetes)