coredns部署

coredns部署

coredns部署

一:coredns-rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: coredns
  namespace: kube-system
  labels:
      kubernetes.io/cluster-service: "true"
      addonmanager.kubernetes.io/mode: Reconcile
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
    addonmanager.kubernetes.io/mode: Reconcile
  name: system:coredns
rules:
- apiGroups:
  - ""
  resources:
  - endpoints
  - services
  - pods
  - namespaces
  verbs:
  - list
  - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
  labels:
    kubernetes.io/bootstrapping: rbac-defaults
    addonmanager.kubernetes.io/mode: EnsureExists
  name: system:coredns
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:coredns
subjects:
- kind: ServiceAccount
  name: coredns
  namespace: kube-system

kubectl create -f coredns-rbac.yaml

二:coredns-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns
  namespace: kube-system
data:
  Corefile: |
    .:53 {
        errors
        log
        health
        ready
        kubernetes cluster.local 10.8.0.0/16  #service资源cluster地址
        forward . 192.168.10.2   #上级DNS地址
        cache 30
        loop
        reload
        loadbalance
       }

kubectl create -f coredns-configmap.yaml

三:coredns-deployment.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: docker.io/coredns/coredns 
        args:
        - -conf
        - /etc/coredns/Corefile
        volumeMounts:
        - name: config-volume
          mountPath: /etc/coredns
        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

kubectl create -f coredns-deployment.yaml

四:coredns-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: coredns
  namespace: kube-system
  labels:
    k8s-app: coredns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "CoreDNS"
spec:
  selector:
    k8s-app: coredns
  clusterIP: 10.8.0.2
  ports:
  - name: dns
    port: 53
    protocol: UDP
  - name: dns-tcp
    port: 53
  - name: metrics
    port: 9153
    protocol: TCP

kubectl create -f coredns-svc.yaml

五:验证

[root@k3 coredns]# kubectl get all -n kube-system -l k8s-app=coredns

NAME READY STATUS RESTARTS AGE

pod/coredns-5c956578dd-5lmwl 1/1 Running 0 2m9s

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

service/coredns ClusterIP 10.8.0.2 53/UDP,53/TCP,9153/TCP 96s

NAME READY UP-TO-DATE AVAILABLE AGE

deployment.apps/coredns 1/1 1 1 2m9s

NAME DESIRED CURRENT READY AGE

replicaset.apps/coredns-5c956578dd 1 1 1 2m9s

[root@k3 coredns]# dig -t A www.baidu.com @192.168.10.2 +short

www.a.shifen.com.

183.232.231.172

183.232.231.174

[root@k3 coredns]# dig -t A www.baidu.com @10.8.0.2 +short

www.a.shifen.com.

183.232.231.172

183.232.231.174

[root@k3 coredns]# kubectl create deployment nginx-dp --image=nginx

deployment.apps/nginx-dp created

[root@k3 coredns]# kubectl get deployments

NAME READY UP-TO-DATE AVAILABLE AGE

nginx-dp 1/1 1 1 9s

[root@k3 coredns]# kubectl get pod

NAME READY STATUS RESTARTS AGE

nginx-dp-6cd9b76579-5dz7t 1/1 Running 0 19s

[root@k3 coredns]# kubectl expose deployment nginx-dp --port=80

service/nginx-dp exposed

[root@k3 coredns]# dig -t A nginx-dp @10.8.0.2 +short

[root@k3 coredns]# dig -t A nginx-dp.default.svc.cluster.local. @10.8.0.2 +short

10.8.223.101

[root@k3 coredns]# kubectl exec -it nginx-dp-6cd9b76579-5dz7t -- cat /etc/resolv.conf

nameserver 10.0.0.2

search default.svc.cluster.local. svc.cluster.local. cluster.local.

options ndots:5

##configmap 解析

 volumes:
  - name: conf
    configMap:
      name: cm-test
      items:
      - key: index.jsp   #key不能写错,cm文件里定义的就是这个
        path: index.jsp  #挂载在容器后叫什么文件名

  • 13
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jane9872

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值