当前位置: 首页 > news >正文

kubernetes集群中部署CoreDNS服务

前言

从k8s 1.11版本开始,k8s集群的dns服务由CoreDNS提供。之前已经使用二进制文件部署了一个三master三node的k8s集群,现在需要在集群内部部署DNS服务。

  • 环境信息
IP说明
192.168.8.21部署了maser和node
192.168.8.22部署了master和node
192.168.8.23部署了master和node
169.169.0.100集群内虚拟IP,DNS地址

步骤

1. 修改node的kubelet启动参数

修改node上的kubelet启动参数,添加以下两个参数,添加完成后重启kubelet。

  • --cluster-dns=169.169.0.100,这是集群内DNS的服务地址
  • --cluster-domain=cluster.local,为在dns服务中设置的域名

2. 部署CoreDNS服务

  1. 创建ConfigMap。主要设置CoreDNS的主配置文件Corefile的内容,其中可以定义各种域名的解析方式和使用的插件。
apiVersion: v1
kind: ConfigMap
metadata:name: corednsnamespace: kube-systemlabels:addonmanager.kubernetes.io/mode: EnsureExists
data:Corefile: |cluster.local {errorshealth {lameduck 5s}readykubernetes cluster.local 169.169.0.0/16 {fallthrough in-addr.arpa ip6.arpa}prometheus :9153forward . /etc/resolv.confcache 30loopreloadloadbalance}. {cache 30loadbalanceforward . /etc/resolv.conf}
  1. 创建deployment。
apiVersion: apps/v1
kind: Deployment
metadata:name: corednsnamespace: kube-systemlabels:k8s-app: kube-dnskubernetes.io/name: "CoreDNS"
spec:replicas: 1strategy:type: RollingUpdaterollingUpdate:maxUnavailable: 1selector:matchLabels:k8s-app: kube-dnstemplate:metadata:labels:k8s-app: kube-dnsspec:priorityClassName: system-cluster-criticaltolerations:- key: "CriticalAddonsOnly"operator: "Exists"nodeSelector:kubernetes.io/os: linuxaffinity:podAntiAffinity:preferredDuringSchedulingIgnoredDuringExecution:- weight: 100podAffinityTerm:labelSelector:matchExpressions:- key: k8s-appoperator: Invalues: ["kube-dns"]topologyKey: kubernetes.io/hostnamecontainers:- name: corednsimage: coredns/coredns:1.10.1imagePullPolicy: IfNotPresentresources:limits:memory: 170Mirequests:cpu: 100mmemory: 70Miargs: [ "-conf", "/etc/coredns/Corefile" ]volumeMounts:- name: config-volumemountPath: /etc/corednsreadOnly: trueports:- containerPort: 53name: dnsprotocol: UDP- containerPort: 53name: dns-tcpprotocol: TCP- containerPort: 9153name: metricsprotocol: TCPsecurityContext:allowPrivilegeEscalation: falsecapabilities:add:- NET_BIND_SERVICEdrop:- allreadOnlyRootFilesystem: truelivenessProbe:httpGet:path: /healthport: 8080scheme: HTTPinitialDelaySeconds: 60timeoutSeconds: 5successThreshold: 1failureThreshold: 5readinessProbe:httpGet:path: /readyport: 8181scheme: HTTPdnsPolicy: Defaultvolumes:- name: config-volumeconfigMap:name: corednsitems:- key: Corefilepath: Corefile
  1. 创建service
apiVersion: v1
kind: Service
metadata:name: kube-dnsnamespace: kube-systemannotations:prometheus.io/port: "9153"prometheus.io/scrape: "true"labels:k8s-app: kube-dnskubernetes.io/cluster-service: "true"kubernetes.io/name: "CoreDNS"
spec:selector:k8s-app: kube-dnsclusterIP: 169.169.0.100ports:- name: dnsport: 53protocol: UDP- name: dns-tcpport: 53protocol: TCP- name: metricsport: 9153protocol: TCP

3. 验证

使用带有nslookup工具的pod来验证dns服务是否正常(《kubernetes权威指南》中用的busybox,但自己测试不行,所以改成了用ubuntu镜像,pod起来后在容器中安装nslookup。):

# pod-ubuntu.yaml
apiVersion: v1
kind: Pod
metadata:name: ubuntunamespace: default
spec:containers:- name: ubuntuimage: ubuntu:22.04command:- sleep- "3600"
  1. 先创建pod
kubectl create -f pod-ubuntu.yaml
  1. 容器启动后,执行命令测试
apt update
apt install -y dnsutils
nslookup svc-nginx

Corefile配置说明

CoreDNS的主要功能是通过插件系统实现的。常用插件如下:

名称说明
loadbalance提供基于DNS的负载均衡功能
loop检测在DNS解析过程中出现的简单循环问题
cache提供前端缓存功能
health对Endpoint进行健康检查
kubernetes从k8s中读取zone数据
etcd从etcd中读取数据,可用于自定义域名记录
file从RFC1035格式文件中读取zone数据
hosts使用/etc/hosts文件或者其他文件读取zone数据,可用于自定义域名记录
auto从磁盘中自动加载区域文件
reload定时自动重新加载Corefile配置文件的内容
forward转发域名查询到上游DNS服务器上
prometheus为Prometheus系统提供采集性能指标数据的URL
pprof在URL路径/debug/pprof下提供运行时的性能数据
log对DNS查询进行日志记录
error对错误信息进行日志记录
http://www.lryc.cn/news/598403.html

相关文章:

  • OceanBase 4.3.5 解析:DDL性能诊断
  • 爆肝整理,性能测试详细汇总,从0到1打通(二)
  • 基于深度学习的胸部 X 光图像肺炎分类系统(三)
  • 在 OceanBase 中,使用 TO_CHAR 函数 直接转换日期格式,简洁高效的解决方案
  • 深入理解 eMMC RPMB 与 OP-TEE 在 Linux 系统中的应用开发
  • 使用宝塔面板搭建 PHP 环境开发一个简单的 PHP 例子
  • 解决VSCode无法加载Json架构问题
  • 《计算机网络》实验报告八 加密、数字签名与证书
  • 力扣844. 比较含退格的字符串
  • 借助Aspose.HTML控件,在 Python 中将 HTML 转换为 Markdown
  • 【bug解决】 esp32 在WSL-ubuntu20.04环境下找不到设备
  • MIT线性代数01_方程组的几何解释
  • 造成服务器内存不足的原因有什么
  • 飞腾D2000/E2000/D3000如何从头制作UBOOT引导系统镜像
  • Pycharm、Python安装及配置小白教程
  • 【docker | 部署 】Jetson Orin与AMD平台容器化部署概述
  • 用LangChain重构客服系统:腾讯云向量数据库+GPT-4o实战
  • 使用爬虫获取游戏的iframe地址
  • DRF - 博客列表API
  • Django Models详解:数据库模型的核心
  • Unity3D + VR头显 × RTSP|RTMP播放器:构建沉浸式远程诊疗系统的技术实践
  • Ascendc msOpST测试报错问题
  • 【Unity开发】数据存储——XML
  • MySQL的命令行客户端
  • Code Composer Studio:CCS 设置代码折叠
  • MySQL零基础教程增删改查实战
  • [语言模型训练]基于 PyTorch 的双向 LSTM 文本分类器实现:基于旅店的评论分类语言模型
  • 与deepseek的问答:dot net与Borland VCL的关系
  • OSPF多区域介绍
  • 【Spring Cloud Gateway 实战系列】高级篇:服务网格集成、安全增强与全链路压测