当前位置: 首页 > 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.dtcms.com/a/296962.html

相关文章:

  • day46day47 通道注意力
  • 一种基于单片机控制的太阳能电池板系统设计
  • 集训Demo6
  • 挖掘录屏宝藏:Screenity 深度解析与使用指南
  • 《计算机网络》实验报告八 加密、数字签名与证书
  • pytest测试框架
  • AUTOSAR进阶图解==>AUTOSAR_SWS_BSWGeneral
  • 【Vue学习笔记】状态管理:Pinia 与 Vuex 的使用方法与对比【附有完整案例】
  • 网络安全入门第一课:信息收集实战手册(2)
  • C语言-指针[变量指针与指针变量]
  • Java 集合框架之----ArrayList
  • Effective Modern C++ 条款16:保证const成员函数的线程安全性
  • 网址收集总结
  • 【硬件-笔试面试题】硬件/电子工程师,笔试面试题-17,(知识点:PCB布线,传输线阻抗影响因素)
  • 第一二章笔记
  • [ComfyUI] --ComfyUI 是什么?比 Stable Diffusion WebUI 强在哪?
  • 【STM32项目】智能台灯
  • 无人机保养指南
  • 深入解析Hadoop NameNode的Full GC问题、堆外内存泄漏及元数据分治策略
  • 软件测试的分类
  • C++实现精确延时的方法
  • 季逸超:Manus的上下文工程启示
  • Photoshop下载安装入门教程:从下载安装到第一次完美使用
  • 应急响应】Linux 自用应急响应工具发版 v6.0(LinuxGun)
  • 20 BTLO 蓝队靶场 Sticky Situation 解题记录
  • Voice AI Agent 知识库:打造你自己的语音智能体!
  • Vitest 用法详解及 Coverage Web 工具介绍
  • C# 密封类_密封方法 (seadled 关键字)
  • 【postgresql按照逗号分割字段,并统计数量和求和】
  • 【Spring AI 1.0.0】Spring AI 1.0.0框架快速入门(4)——Chat Memory(聊天记录)