公司内网安装dns,然后把域名ning.com直接指向ingress-nginx的ip

Posted blackmood

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了公司内网安装dns,然后把域名ning.com直接指向ingress-nginx的ip相关的知识,希望对你有一定的参考价值。

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 及完成

以上是关于公司内网安装dns,然后把域名ning.com直接指向ingress-nginx的ip的主要内容,如果未能解决你的问题,请参考以下文章

公司内网搭建代理DNS使用内网域名代替ip地址

公司内网搭建代理DNS使用内网域名代替ip地址

为啥要设置内网DNS

内网dns配置

两个公司网域经VPN连通,A域DNS服务器能解析外网和内网域名,B域有一台应用服务器做了外网和内网域名解析

网络 -- DNS的原理与应用