kubernetes(九)二进制安装-CoreDns安装

部署 coredns 插件(在master节点上执行)

  1. 下载和配置 coredns

    cd /opt/k8s/work
    git clone https://github.com/coredns/deployment.git
    mv deployment coredns
    
    
  2. 启动 coredns
    cd /opt/k8s/work/coredns/kubernetes
    
    export CLUSTER_DNS_SVC_IP="10.254.0.2"
    export CLUSTER_DNS_DOMAIN="cluster.local"
    
    ./deploy.sh -i ${CLUSTER_DNS_SVC_IP} -d ${CLUSTER_DNS_DOMAIN} | kubectl apply -f -
    
  3. 遇到问题

    启动coredns后,状态是CrashLoopBackOff

    [email protected]:/opt/k8s/work/coredns/kubernetes# kubectl get pod -n kube-system -l k8s-app=kube-dns
    NAME                      READY   STATUS             RESTARTS   AGE
    coredns-76b74f549-99bxd   0/1     CrashLoopBackOff   5          4m45s
    

    查看coredns对应的pod日志有如下错误

    [email protected]:/opt/k8s/work/coredns/kubernetes# kubectl -n kube-system logs coredns-76b74f549-99bxd
    .:53
    [INFO] plugin/reload: Running configuration MD5 = 8b19e11d5b2a72fb8e63383b064116a1
    CoreDNS-1.6.6
    linux/amd64, go1.13.5, 6a7a75e
    [FATAL] plugin/loop: Loop (127.0.0.1:60429 -> :53) detected for zone ".", see https://coredns.io/plugins/loop#troubleshooting. Query: "HINFO 6292641803451309721.7599235642583168995."
    
    

    按照提示进入https://coredns.io/plugins/loop#troubleshooting页面,有如下表述

    When a CoreDNS Pod deployed in Kubernetes detects a loop, the CoreDNS Pod will start to “CrashLoopBackOff”. This is because Kubernetes will try to restart the Pod every time CoreDNS detects the loop and exits.

    A common cause of forwarding loops in Kubernetes clusters is an interaction with a local DNS cache on the host node (e.g. systemd-resolved). For example, in certain configurations systemd-resolved will put the loopback address 127.0.0.53 as a nameserver into /etc/resolv.conf. Kubernetes (via kubelet) by default will pass this /etc/resolv.conf file to all Pods using the default dnsPolicy rendering them unable to make DNS lookups (this includes CoreDNS Pods). CoreDNS uses this /etc/resolv.conf as a list of upstreams to forward requests to. Since it contains a loopback address, CoreDNS ends up forwarding requests to itself.

    There are many ways to work around this issue, some are listed here:

    • Add the following to your kubelet config yaml: resolvConf: (or via command line flag --resolv-conf deprecated in 1.10). Your “real” resolv.conf is the one that contains the actual IPs of your upstream servers, and no local/loopback address. This flag tells kubelet to pass an alternate resolv.conf to Pods. For systems using systemd-resolved, /run/systemd/resolve/resolv.conf is typically the location of the “real” resolv.conf, although this can be different depending on your distribution.
    • Disable the local DNS cache on host nodes, and restore /etc/resolv.conf to the original.
    • A quick and dirty fix is to edit your Corefile, replacing forward . /etc/resolv.conf with the IP address of your upstream DNS, for example forward . 8.8.8.8. But this only fixes the issue for CoreDNS, kubelet will continue to forward the invalid resolv.conf to all default dnsPolicy Pods, leaving them unable to resolve DNS.

    按照提示的第一种解决方法,修改kubelet对应的配置文件kubelet-config.yaml中resolv-conf的值为/run/systemd/resolve/resolv.conf,配置片段如下

    ...
    
    podPidsLimit: -1
    resolvConf: /run/systemd/resolve/resolv.conf
    maxOpenFiles: 1000000  
    
    ...
    
    

    重启kubelet服务

    systemctl daemon-reload
    systemctl restart kubelet
    

    之后重新部署coredns

    
    [email protected]:/opt/k8s/work/coredns/kubernetes# ./deploy.sh -i ${CLUSTER_DNS_SVC_IP} -d ${CLUSTER_DNS_DOMAIN} | kubectl apply -f -
    serviceaccount/coredns created
    clusterrole.rbac.authorization.k8s.io/system:coredns created
    clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
    configmap/coredns created
    deployment.apps/coredns created
    service/kube-dns created
    
    [email protected]:/opt/k8s/work/coredns/kubernetes# kubectl get pod -A
    NAMESPACE     NAME                      READY   STATUS    RESTARTS   AGE
    kube-system   coredns-76b74f549-j5t9c   1/1     Running   0          12s
    
    [email protected]:/opt/k8s/work/coredns/kubernetes# kubectl get all -n kube-system  -l k8s-app=kube-dns
    NAME                          READY   STATUS    RESTARTS   AGE
    pod/coredns-76b74f549-j5t9c   1/1     Running   0          2m8s
    
    NAME               TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
    service/kube-dns   ClusterIP   10.254.0.2   <none>        53/UDP,53/TCP,9153/TCP   2m8s
    
    NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
    deployment.apps/coredns   1/1     1            1           2m8s
    
    NAME                                DESIRED   CURRENT   READY   AGE
    replicaset.apps/coredns-76b74f549   1         1         1       2m8s
    
    
  4. 启动一个busybox pod,并启动上一章节中验证集群功能的nginx服务,在busybox通过服务名,访问nginx服务
    cd /opt/k8s/yml
    cat > busybox.yml << EOF
    apiVersion: v1
    kind: Pod
    metadata:
      name: busybox
    spec:
      containers:
      - name: busybox
        image: busybox
        command:
          - sleep
          - "3600"
    EOF
    
    kubectl create -f busybox.yml
    
    kubectl create -f nginx.yml
    
    
  5. 进入busybox pod中访问nginx
    [email protected]:/opt/k8s/yml# kubectl exec -it busybox  sh
    / # cat /etc/resolv.conf
    nameserver 10.254.0.2
    search default.svc.cluster.local svc.cluster.local cluster.local
    options ndots:5 
    
    / # nslookup www.baidu.com
    Server:         10.254.0.2
    Address:        10.254.0.2:53
    
    Non-authoritative answer:
    www.baidu.com   canonical name = www.a.shifen.com
    Name:   www.a.shifen.com
    Address: 183.232.231.174
    Name:   www.a.shifen.com
    Address: 183.232.231.172 
    
    / # nslookup kubernetes
    Server:         10.254.0.2
    Address:        10.254.0.2:53
    
    Name:   kubernetes.default.svc.cluster.local
    Address: 10.254.0.1
    
    / # nslookup nginx
    Server:         10.254.0.2
    Address:        10.254.0.2:53
    
    Name:   nginx.default.svc.cluster.local
    Address: 10.254.19.32
    
    / # ping -c 1 nginx
    PING nginx (10.254.19.32): 56 data bytes
    64 bytes from 10.254.19.32: seq=0 ttl=64 time=0.155 ms
    
    --- nginx ping statistics ---
    1 packets transmitted, 1 packets received, 0% packet loss
    round-trip min/avg/max = 0.155/0.155/0.155 ms
    
    

原文地址:https://www.cnblogs.com/gaofeng-henu/p/12594651.html

时间: 2024-10-09 03:54:04

kubernetes(九)二进制安装-CoreDns安装的相关文章

kubernetes实战(三十):CentOS 8 二进制 高可用 安装 k8s 1.17.x

1. 基本说明 本文章将演示CentOS 8二进制方式安装高可用k8s 1.17.x,相对于其他版本,二进制安装方式并无太大区别. 2. 基本环境配置 主机信息 192.168.1.19 k8s-master01 192.168.1.18 k8s-master02 192.168.1.20 k8s-master03 192.168.1.88 k8s-master-lb 192.168.1.21 k8s-node01 192.168.1.22 k8s-node02 系统环境 [[email pro

Kubernetes1.12版本Dashboard和coredns安装

一.部署Web UI(Dashboard)1.解压包,进入目录包就在之前的master部署组件里这里里面kubernetes-server-linux-amd64.tar.gz 2.执行yaml文件 查看启动的pod,没在默认命名空间,在kube-system下 注:其中dashboard-controller.yaml这个里面的dashboard镜像是国外的,如果慢,可以换成国内的镜像地址 image: registry.cn-hangzhou.aliyuncs.com/google_cont

K8S 之 Coredns安装与理解

一.Coredns作用 重点:通过coredns 通过service名称,解释到相应的cluter集群IP 二.Coredns安装(以容器搭建服务) 1.在运维主机上搭建一个HTTP服务存放yaml文件 ~]# cd /etc/nginx/conf.d/ conf.d]# vi /etc/nginx/conf.d/k8s-yaml.od.com.conf server { listen 80; server_name k8s-yaml.od.com; location / { autoindex

centos7 二进制安装包安装 mysql5.6

一.下载mysql5.6二进制安装包 http://mirrors.sohu.com/mysql/MySQL-5.6/ 如:mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz 二.安装mysql5.6(安装在/data/mysql56) (1).创建mysql用户账号 > useradd -s /sbin/nologin -M mysql (2).解压压缩包 > tar xf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz (

MySQL简介以及二进制程序方式安装

数据的组织结构 层次型 网状型 关系型 使用DBMS的优点 1,数据管理独立性: 2,有效的完成数据存取: 3,保证数据完整性和安全性: 4,数据的集中管理: 5,并发存储与故障恢复: 6,减少应用程序开发时间: 数据库管理系统(DBMS)设计的目标 为了解决: 1,数据的冗余和不一致: 2,数据访问困难: 3,数据孤立: 4,数据完整性问题: 5,数据原子性问题: 6,并发访问问题: 7,安全性问题: DBMS的组件 1,分析器: 2,计划执行器: 3,优化器: 4,文件的存取方法: 5,缓存

基于二进制通用格式安装mysql-5.5.52

基于二进制通用格式安装mysql-5.5.52 环境介绍: Linux主机:centos6.8 mysql二进制格式包:mysql-5.5.52-linux2.6-x86_64.tar.gz 1.解压包到特定目录 [[email protected] ~]# tar xf mysql-5.5.52-linux2.6-x86_64.tar.gz -C /usr/local/ 2.创建软链接 [[email protected] ~]# ln -sv /usr/local/mysql-5.5.52-

二进制方式快速安装MySQL数据库命令集合

镜像源: http://mirrors.sohu.com/ 1.二进制方式快速安装MySQL数据库命令集合 1.安装mysqlcd /usr/local/srcwget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.48-linux2.6-x86_64.tar.gzls mysql-5.5.32-linux2.6-x86_64.tar.gztar xf mysql-5.5.32-linux2.6-x86_64.tar.gz mv mysql-

MySQL安装:MariaDB二进制包方式安装

MySQL那是相当流行的关系型数据库有之一,随着MySQL被Oracle收购后开源的前途未卜,gooogle, 非死不可等都开始转入mysql开源社区维护的另一个开源mysql分支MariaDB上去了,Maria是mysql创始人Michael Widenius的二女儿的名字,MariaDB完全兼容MySQL, 使用Percona维护的XtraDB(代号Aria)来代替InnoDB引擎,比InnoDB有很多优化等,另外对并行复制(Parallel Replication).多源复制(Muti-S

【MySQL】Linux下MySQL 5.5、5.6和5.7的RPM、二进制和源码安装

  [MySQL]Linux下MySQL 5.5.5.6和5.7的RPM.二进制和源码安装 1.1  BLOG文档结构图 1.2  前言部分 1.2.1  导读和注意事项 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ① MySQL的二进制安装过程(重点) ② MySQL多实例管理(mysqld_multi) ③ MySQL的源码编译安装过程 ④ Linux的逻辑卷的使用 ⑤ 文件的MD5值 ⑥ 访问MySQL的几种客户端工具(Nav