3. kubernetes 의 서비스 발견 플러그 인 - CoreDNS (운영 기술 교류 군: 926402931, 모두 가 함께 교류 하 는 것 을 환영 합 니 다.)

5968 단어
목차
  • 1. kubernetesubernetes 를 배치 하 는 네트워크 자원 설정 목록
  • 2. dns 분석 설정
  • 3. 브 라 우 저 k8s - yaml. od. com 방문
  • 4. docker 미 러 를 다운로드 하여 harbor 창고 에 포장 하여 업로드
  • 5. 자원 배분 목록 준비
  • 6. 응용 자원 설정
  • 7. 생 성 된 자원 검사
  • 8. coreDNS 검증
  • 1. kubernetesubernetes 를 배치 하 는 네트워크 자원 설정 목록
    hdss7 - 200. host. com 에 서 는 kubernetes 의 통 일 된 방문 자원 목록 입 구 를 제공 하기 위해 NGINX 를 설정 합 니 다.
    [root@hdss7-200 html]# vi /etc/nginx/conf.d/k8s-yaml.od.com.conf
    server {
        listen       80;
        server_name  k8s-yaml.od.com;
    
        location / {
            autoindex on;
            default_type text/plain;
            root /data/k8s-yaml;
        }
    }
    [root@hdss7-200 html]# nginx -t
    [root@hdss7-200 html]# nginx -s reload
    [root@hdss7-200 html]# cd /data
    [root@hdss7-200 data]# mkdir k8s-yaml
    [root@hdss7-200 data]# cd k8s-yaml/
    [root@hdss7-200 k8s-yaml]# mkdir coredns
    

    2. dns 분석 설정
    [root@hdss7-11 ~]# vi /var/named/od.com.zone
    $ORIGIN od.com.
    $TTL 600        ; 10 minutes
    @               IN SOA  dns.od.com. dnsadmin.od.com. (
                                    2019111003 ; serial
                                    10800      ; refresh (3 hours)
                                    900        ; retry (15 minutes)
                                    604800     ; expire (1 week)
                                    86400      ; minimum (1 day)
                                    )
                                    NS   dns.od.com.
    $TTL 60 ; 1 minute
    dns                A    10.4.7.11
    harbor             A    10.4.7.200
    k8s-yaml           A    10.4.7.200
    
    [root@hdss7-11 ~]# systemctl restart named
    [root@hdss7-11 ~]# dig -t A k8s-yaml.od.com @10.4.7.11 +short
    10.4.7.200
    

    3. 브 라 우 저 k8s - yaml. od. com 방문
    4. docker 미 러 를 다운로드 하여 harbor 창고 에 포장 하여 업로드
    [root@hdss7-200 ~]# docker pull coredns/coredns:1.6.1
    [root@hdss7-200 coredns]# docker tag c0f6e815079e harbor.od.com/public/coredns:v1.6.1
    [root@hdss7-200 coredns]# docker  push harbor.od.com/public/coredns:v1.6.1
    

    5. 자원 설정 목록 준비
    rbac.yaml
    [root@hdss7-200 coredns]# vi 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
    

    cm.yaml
    [root@hdss7-200 coredns]# vi cm.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: coredns
      namespace: kube-system
    data:
      Corefile: |
        .:53 {
            errors
            log
            health
            ready
            kubernetes cluster.local 192.168.0.0/16
            forward . 10.4.7.11
            cache 30
            loop
            reload
            loadbalance
           }
    

    dp.yaml
    [root@hdss7-200 coredns]# vi 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: harbor.od.com/public/coredns:v1.6.1
            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
    

    svc.yaml
    [root@hdss7-200 coredns]# vi 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: 192.168.0.2
      ports:
      - name: dns
        port: 53
        protocol: UDP
      - name: dns-tcp
        port: 53
      - name: metrics
        port: 9153
        protocol: TCP
    

    6. 자원 설정 적용
    [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/rbac.yaml
    [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/cm.yaml
    [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/dp.yaml
    [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/svc.yaml
    

    7. 생 성 된 자원 검사
    [root@hdss7-21 ~]# kubectl get all -n kube-system -o wide
    

    8. 코어 DNS 검증
    [root@hdss7-21 ~]# dig -t A www.baidu.com @192.168.0.2 +short
    www.a.shifen.com.
    14.215.177.38
    14.215.177.39
    

    좋은 웹페이지 즐겨찾기