Kubernetes 1.5 配置dns

Kubernetes 1.5 配置dns

  在kubernetes1.2的时候,采用了skydns + kube2dns +etcd的方式来部署dns。而从1.3开始,则部署方式有了一点儿变化,将skydns和kube2dns封装到了一个容器镜像中,放弃了etcd,而将dns解析直接放入到了内存之中,同时引入了dnsmasq,进一步利用其缓存,具体的原理,请查阅相关文档。本篇文档,主要阐述新版的dns在kubernetes中的具体部署。

  在Kubernetes的源码目录中,有个cluster/addons/dns目录,下面有几个与dns相关的文件,我们将其中的skydns-rc.yaml.sed以及skydns-svc.yaml.sed文件下载到本地,并去掉后缀。只是拷贝文件的话,可以通过https://rawgit.com这个地址加速,如下:

wget https://rawgit.com/kubernetes/kubernetes/release-1.5/cluster/addons/dns/skydns-rc.yaml.sed -O skydns-rc.yaml
wget https://rawgit.com/kubernetes/kubernetes/release-1.5/cluster/addons/dns/skydns-svc.yaml.sed -O skydns-svc.yaml

下载下来的原文件是用于saltstack自动化安装的,我们手动处理的时候,需要进行相关修改。

修改skydns-rc.yaml内容如下:

# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO - At some point, we need to rename all skydns-*.yaml.* files to kubedns-*.yaml.*
# Should keep target in cluster/addons/dns-horizontal-autoscaler/dns-horizontal-autoscaler.yaml
# in sync with this file.

# __MACHINE_GENERATED_WARNING__

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: kube-dns
  namespace: kube-system
  labels:
    k8s-app: kube-dns
    kubernetes.io/cluster-service: "true"
spec: #指定副本数
  replicas: 1
  # replicas: not specified here:
  # 1. In order to make Addon Manager do not reconcile this replicas parameter.
  # 2. Default is 1.
  # 3. Will be tuned in real time if DNS horizontal auto-scaling is turned on.
  strategy:
    rollingUpdate:
      maxSurge: 10%
      maxUnavailable: 0
  selector:
    matchLabels:
      k8s-app: kube-dns
  template:
    metadata:
      labels:
        k8s-app: kube-dns
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ‘‘
        scheduler.alpha.kubernetes.io/tolerations: ‘[{"key":"CriticalAddonsOnly", "operator":"Exists"}]‘
    spec:
      containers:
      - name: kubedns     #修改image地址,默认是google的仓库地址,如果不担心被墙,可以直接使用,我这里使用的私有仓库地址,如果要使用国内其他仓库地址,推荐使用阿里云镜像库
        image: myhub.fdccloud.com/library/kubedns-amd64:1.9
        resources:
          # TODO: Set memory limits when we‘ve profiled the container for large
          # clusters, then set request = limit to keep this container in
          # guaranteed class. Currently, this container falls into the
          # "burstable" category so the kubelet doesn‘t backoff from restarting it.
          limits:
            memory: 170Mi
          requests:
            cpu: 100m
            memory: 70Mi
        livenessProbe:
          httpGet:
            path: /healthz-kubedns
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        readinessProbe:
          httpGet:
            path: /readiness
            port: 8081
            scheme: HTTP
          # we poll on pod startup for the Kubernetes master service and
          # only setup the /readiness HTTP server once that‘s available.
          initialDelaySeconds: 3
          timeoutSeconds: 5
        args:     # --domain指定一级域名,可自定义
        - --domain=cluster.local.
        - --dns-port=10053
        - --config-map=kube-dns     #增加--kube-master-url,指向kube master的地址
        - --kube-master-url=http://10.5.10.116:8080
        # This should be set to v=2 only after the new image (cut from 1.5) has
        # been released, otherwise we will flood the logs.
        - --v=0
        #__PILLAR__FEDERATIONS__DOMAIN__MAP__
        env:
        - name: PROMETHEUS_PORT
          value: "10055"
        ports:
        - containerPort: 10053
          name: dns-local
          protocol: UDP
        - containerPort: 10053
          name: dns-tcp-local
          protocol: TCP
        - containerPort: 10055
          name: metrics
          protocol: TCP
      - name: dnsmasq
        image: myhub.fdccloud.com/library/kube-dnsmasq-amd64:1.4
        livenessProbe:
          httpGet:
            path: /healthz-dnsmasq
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        args:
        - --cache-size=1000
        - --no-resolv
        - --server=127.0.0.1#10053
        #- --log-facility=-  #注释掉该行
        ports:
        - containerPort: 53
          name: dns
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
        # see: https://github.com/kubernetes/kubernetes/issues/29055 for details
        resources:
          requests:
            cpu: 150m
            memory: 10Mi
      - name: dnsmasq-metrics
        image: myhub.fdccloud.com/library/dnsmasq-metrics-amd64:1.0
        livenessProbe:
          httpGet:
            path: /metrics
            port: 10054
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        args:
        - --v=2
        - --logtostderr
        ports:
        - containerPort: 10054
          name: metrics
          protocol: TCP
        resources:
          requests:
            memory: 10Mi
      - name: healthz
        image: myhub.fdccloud.com/library/exechealthz-amd64:1.2
        resources:
          limits:
            memory: 50Mi
          requests:
            cpu: 10m
            # Note that this container shouldn‘t really need 50Mi of memory. The
            # limits are set higher than expected pending investigation on #29688.
            # The extra memory was stolen from the kubedns container to keep the
            # net memory requested by the pod constant.
            memory: 50Mi
        args:
        - --cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 >/dev/null
        - --url=/healthz-dnsmasq
        - --cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1:10053 >/dev/null
        - --url=/healthz-kubedns
        - --port=8080
        - --quiet
        ports:
        - containerPort: 8080
          protocol: TCP
      dnsPolicy: Default  # Don‘t use cluster DNS.

修改skydns-svc.yaml内容如下:

# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# TODO - At some point, we need to rename all skydns-*.yaml.* files to kubedns-*.yaml.*

# __MACHINE_GENERATED_WARNING__

apiVersion: v1
kind: Service
metadata:
  name: kube-dns
  namespace: kube-system
  labels:
    k8s-app: kube-dns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "KubeDNS"
spec:
  selector:
    k8s-app: kube-dns  #指定clusterIP,后面各pod的dns地址都会指向该地址
  clusterIP: 10.254.0.100
  ports:
  - name: dns
    port: 53
    protocol: UDP
  - name: dns-tcp
    port: 53
    protocol: TCP

启动dns:

kubectl create -f skydns-rc.yaml
kubectl create -f skydns-svc.yaml

修改各node节点上的/etc/kubernetes/kubelet配置文件,增加如下行:

KUBELET_ARGS="--cluster_dns=10.254.0.100 --cluster_domain=cluster.local"

重启各节点:

systemctl restart kubelet

添加一个busybox的pod用于测试,busybox.yaml内容如下:

apiVersion: v1
kind: Pod
metadata:
  labels:
    name: busybox
    role: master
  name: busybox
spec:
  containers:
  - name: busybox
    image: myhub.fdccloud.com/library/busybox
    command:
    - sleep
    - "3600"

执行如下操作:

kubectl exec -it busybox sh
nslookup kubernetes
nslookup kubernetes.default.cluster.local
nslookup kubernetes.default.svc.cluster.local

如果能正常解析,则部署OK。

时间: 2024-08-26 14:52:03

Kubernetes 1.5 配置dns的相关文章

ubuntu配置DNS

众所周知,centos配置DNS很简单,修改下/etc/resolv.conf,就可以生效.但是ubuntu中,resolv.conf文件却说明写入会被覆盖,不能写在这里. 方法一: 修改/etc/network/interfaces(interfaces文件是万能的,能配IP.路由.DNS) dns-nameservers 114.114.114.114 方法二: 修改/etc/resolvconf/resolv.conf.d/base文件,该文件默认是空的.(或者新建tail文件写入name

CentOS5.5 下配置DNS

1.配置网卡IP地址 #ifconfig   eth0   192.168.186.188 2.关闭防火墙 #iptables -F 3.安装软件 所需要的软件:bind和caching-name #rpm  -ivh  bind-9.3.6-4.P1.el5 #rpm  -ivh  caching-nameserver-9.3.6-4.P1.el5 4.修改named.conf 配置文件 修改named.caching-nameserver.conf #cp /etc/named.cachin

配置DNS服务器

一.配置基本的DNS 服务器(包含正向解析和反向解析)域名:abc.com服务器IP:10.1.2.11 1. 编辑主配置文件/etc/named.conf----------------------------------------------------options { listen-on port 53 { any; }; <-- 改为any,监听所有本地IP地址 listen-on-v6 port 53 { ::1; }; directory "/var/named"

RedHat 6配置DNS服务实现主从同步与正反向解析

本文介绍RedHat 6简单配置DNS服务器,主要包括主从同步与正反向解析. 一.测试环境 主DNS服务器:DNS01:192.168.10.1 从DNS服务器:DNS02:192.168.10.2 操作系统:Red Hat Enterprise Linux Server release 6.5 二.安装配置主DNS服务器 1.在dns01安装所需的包,其中bind包提供域名服务的主要程序及相关文件.bind-chroot包提供一个伪根目录,使得bind被限制在这个牢笼中运行,保护真正的根目录以

&lt;转&gt;配置DNS辅助服务器:DNS系列之四

配置DNS辅助服务器 在前面的博文中,我们介绍了如何在DNS服务器中创建常用的DNS记录,本文中我们要为大家介绍如何配置DNS的辅助服务器,同时也要介绍一下和辅助区域类似的存根区域. DNS辅助服务器是一种容错设计,考虑的是一旦DNS主服务器出现故障或因负载太重无法及时响应客户机请求,辅助服务器将挺身而出为主服务器排忧解难.辅助服务器的区域数据都是从主服务器复制而来,因此辅助服务器的数据都是只读的,当然,如果有必要,我们可以很轻松地把辅助服务器升级为主服务器.我们通过下面的一个实验为大家介绍如何

配置DNS的正反向解析与主从同步

配置DNS的正反向解析与主从同步 准备: 本实验基于两台centos6.5其内核版本号为2.6.32-431.el6.x86_64 配置时间同步 # echo "#update system date by jiajie at 20170506" >>/var/spool/cron/root  # echo "*/5 * * * * /usr/sbin/ntpdate time.nist.gov > /dev/null 2>&1" &

如何配置DNS服务器(局域网——域名指向某个IP地址)

单击“开始”,指向“管理工具”,然后单击“DNS”,打开 DNS 管理器.   如有必要,向管理单元添加适用的服务器,然后连接该服务器.在控制台树中,单击适用的 DNS 服务器.   在“操作”菜单上,单击“配置 DNS 服务器”.打开DNS服务配置向导   然后根据公司规模大小来选择查找区域类型,点击“下一步”主服务器配置界面   如果本机做为DNS服务器,则选择第一项,如果是配置网络上的一台DNS服务器则选择ISP维护区域,选择后点击“下一步”进入区域名称选择窗口.   输入区域名称后点击“

学习记录——配置DNS服务器

一实验准备工作 主DNS服务器 1.配置主机域名 [[email protected] ~]# hostname xuan.com   ///临时修改名,永久修改需要去/etc/sysconfig/network 修改.然后记住在/etc/hosts 里更新自己的域,为了方便实验,先修改了名字 2.取消dhcp,ip地址改为静态 3.安装DNS [[email protected] -]# yum -y install bind 二配置DNS服务器 1.查看安装文件目录 [[email prot

redhat 6.5 & windows 配置DNS服务器

场景描述: 某客户处,企业内有多台Linux搭建的DNS服务器,也有多台windows 搭建的DNS服务器.某客户想把Linux的DNS服务器添加到windows 的DNS服务器上的"反向查找区域".如下图所示: 环境搭建: 说明:windows的DNS服务器搭建略过,本文将重点介绍使用redhat 6.5搭建DNS服务器. Redhat 6.5搭建DNS服务器之环境介绍: 一台windows DNS服务器,计算机名:dc01.contoso.com,IP:192.168.10.10