k8s dns 服务安装配置说明
1. 提前条件
安装k8s 集群
2. dns 安装配置
安装方式: 使用controller service
controller 脚本:
基于官方改动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | apiVersion: v1 kind: ReplicationController metadata: name: kube-dns-v8 namespace : kube-system labels: k8s-app: kube-dns version: v8 kubernetes.io/cluster-service: "true" spec: replicas: 1 selector: k8s-app: kube-dns version: v8 template: metadata: labels: k8s-app: kube-dns version: v8 kubernetes.io/cluster-service: "true" spec: containers: - name: etcd image: tlitiwwhtmi/etcd resources: limits: cpu: 100m memory: 50Mi command: - /usr/local/bin/etcd - -data-dir - / var /etcd/data - -listen-client-urls - http: //127.0.0.1:2379,http://127.0.0.1:4001 - -advertise-client-urls - http: //127.0.0.1:2379,http://127.0.0.1:4001 - -initial-cluster-token - skydns-etcd volumeMounts: - name: etcd-storage mountPath: / var /etcd/data - name: kube2sky image: outrider/kube2sky resources: limits: cpu: 100m memory: 50Mi args: # command = "/kube2sky" - --domain=cluster.local - --kube_master_url=http: //10.25.143.50:8080 - name: skydns image: outrider/skydns resources: limits: cpu: 100m memory: 50Mi args: # command = "/skydns" - -machines=http: //localhost:4001 - -addr=0.0.0.0:53 - -domain=cluster.local ports: - containerPort: 53 name: dns protocol: UDP - containerPort: 53 name: dns-tcp protocol: TCP livenessProbe: httpGet: path: /healthz port: 8080 scheme: HTTP initialDelaySeconds: 30 timeoutSeconds: 5 - name: healthz image: outrider/exechealthz resources: limits: cpu: 10m memory: 20Mi args: - -cmd=nslookup kubernetes. default .svc.cluster.local localhost >/dev/ null - -port=8080 ports: - containerPort: 8080 protocol: TCP volumes: - name: etcd-storage emptyDir: {} dnsPolicy: Default # Don't use cluster DNS. |
service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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: 10.254.0.3 ports: - name: dns port: 53 protocol: UDP - name: dns-tcp port: 53 protocol: TCP |
创建namespace
1 2 3 4 | apiVersion: v1 kind: Namespace metadata: name: kube-system |
3. node 进行 dns 配置
在启动脚本添加:
1 2 | --cluster-dns=10.254.0.3 \ --cluster-domain=cluster.local |
4. 重启node
5. 测试pod
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | apiVersion: v1 kind: Pod metadata: name: busybox namespace : default spec: containers: - image: busybox command: - sleep - "3600" imagePullPolicy: IfNotPresent name: busybox restartPolicy: Always |
6. 测试
1 | kubectl exec busybox -- nslookup ngservice |
测试结果
1 2 3 4 5 | Server: 10.254.0.3 Address 1: 10.254.0.3 Name: ngservice Address 1: 10.254.52.109 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2014-11-17 C# 判断操作系统的位数