k8s搭建自定义dns
  TEZNKK3IfmPf 2023年11月15日 28 0


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"]



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月15日 0

暂无评论

推荐阅读
  TEZNKK3IfmPf   2023年11月15日   31   0   0 edn
  TEZNKK3IfmPf   2023年11月15日   29   0   0 edn配置文件
TEZNKK3IfmPf