coredns-新增hosts信息-域名解析

1.修改corednsconfigmap

 

hosts /etc/add-hosts/customer-hosts . {
fallthrough .
}

 

kubectl edit cm coredns -n kube-system

[root@mycloud1-001 coredns]# cat cm.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
        errors
        health {
            lameduck 5s
        }
        ready
        kubernetes cluster.local in-addr.arpa ip6.arpa {
           pods insecure
           fallthrough in-addr.arpa ip6.arpa
           ttl 30
        }
        hosts /etc/add-hosts/customer-hosts . {  #新增信息
           fallthrough .
        }
        prometheus :9153
        forward . /etc/resolv.conf
        cache 30
        loop
        reload
        loadbalance
    }

2.修改coredns的deployment

- mountPath: /etc/add-hosts
name: customer-hosts1
readOnly: true

 

- configMap:
defaultMode: 420
items:
- key: customer-hosts
path: customer-hosts
name: coredns-customer-hosts
name: customer-hosts1

coredns-新增hosts信息-域名解析
kubectl edit deploy coredns -n kube-system
[root@mycloud1-001 coredns]# cat dp.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: coredns
  namespace: kube-system
  labels:
    k8s-app: coredns
    kubernetes.io/name: "CoreDNS"
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: coredns
  template:
    metadata:
      labels:
        k8s-app: coredns
    spec:
      priorityClassName: system-cluster-critical
      serviceAccountName: coredns
      containers:
      - name: coredns
        image: coredns/coredns:latest
        args:
        - -conf
        - /etc/coredns/Corefile
        volumeMounts:
        - name: config-volume
          mountPath: /etc/coredns
        - mountPath: /etc/add-hosts  #新增
          name: customer-hosts1
          readOnly: true
        ports:
        - containerPort: 53
          name: dns
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
        - containerPort: 9153
          name: metrics
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
      dnsPolicy: Default
      volumes:
        - name: config-volume
          configMap:
            name: coredns
            items:
            - key: Corefile
              path: Corefile
        - configMap:
            defaultMode: 420
            items:
            - key: customer-hosts
              path: customer-hosts
            name: coredns-customer-hosts
          name: customer-hosts1  #新增
View Code

3.新增的hosts

[root@mycloud1-001 coredns]# cat customer-host.yaml 
---
apiVersion: v1
data:
  customer-hosts: |
    #数据库ip
    192.168.1.2 vip.clmdb.op.core
    10.224.158.181  vip.coredb.op.core    

kind: ConfigMap
metadata:
  name: coredns-customer-hosts
  namespace: kube-system

4.测试 。可以解析域名了

coredns-新增hosts信息-域名解析

 

 

 

 coredns-新增hosts信息-域名解析

 

coredns-新增hosts信息-域名解析

上一篇:Redis07---主从复制


下一篇:tomcat+crontab 定时重启