k8s dns 服务安装配置说明
Posted rongfengliang-荣锋亮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s dns 服务安装配置说明相关的知识,希望对你有一定的参考价值。
1. 提前条件
安装k8s 集群
2. dns 安装配置
安装方式: 使用controller service
controller 脚本:
基于官方改动
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
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
apiVersion: v1 kind: Namespace metadata: name: kube-system
3. node 进行 dns 配置
在启动脚本添加:
--cluster-dns=10.254.0.3 --cluster-domain=cluster.local
4. 重启node
5. 测试pod
apiVersion: v1 kind: Pod metadata: name: busybox namespace: default spec: containers: - image: busybox command: - sleep - "3600" imagePullPolicy: IfNotPresent name: busybox restartPolicy: Always
6. 测试
kubectl exec busybox -- nslookup ngservice
测试结果
Server: 10.254.0.3 Address 1: 10.254.0.3 Name: ngservice Address 1: 10.254.52.109
以上是关于k8s dns 服务安装配置说明的主要内容,如果未能解决你的问题,请参考以下文章
K8S运维知识汇总第2天2:准备服务器+安装bind9DNS服务
项目环境搭建Docker+k8s五 || 部署自建DNS系统
安装 局域网用的dns服务器,为多环境k8s的ip地址解耦合