kubernetes的服务发现插件-CoreDNS
程序员文章站
2022-09-17 15:07:24
[TOC] 1.部署kubernetesubernetes的内网资源配置清单 在hdss7 200.host.com上,配置一个NGINX,用以提供kubernetes统一的访问资源清单入口 2.配置dns解析 3.浏览器访问k8s yaml.od.com 4.下载docker镜像并打包上传到har ......
1.部署kubernetesubernetes的内网资源配置清单
在hdss7-200.host.com上,配置一个nginx,用以提供kubernetes统一的访问资源清单入口
[root@hdss7-200 html]# vi /etc/nginx/conf.d/k8s-yaml.od.com.conf server { listen 80; server_name k8s-yaml.od.com; location / { autoindex on; default_type text/plain; root /data/k8s-yaml; } } [root@hdss7-200 html]# nginx -t [root@hdss7-200 html]# nginx -s reload [root@hdss7-200 html]# cd /data [root@hdss7-200 data]# mkdir k8s-yaml [root@hdss7-200 data]# cd k8s-yaml/ [root@hdss7-200 k8s-yaml]# mkdir coredns
2.配置dns解析
[root@hdss7-11 ~]# vi /var/named/od.com.zone $origin od.com. $ttl 600 ; 10 minutes @ in soa dns.od.com. dnsadmin.od.com. ( 2019111003 ; serial 10800 ; refresh (3 hours) 900 ; retry (15 minutes) 604800 ; expire (1 week) 86400 ; minimum (1 day) ) ns dns.od.com. $ttl 60 ; 1 minute dns a 10.4.7.11 harbor a 10.4.7.200 k8s-yaml a 10.4.7.200 [root@hdss7-11 ~]# systemctl restart named [root@hdss7-11 ~]# dig -t a k8s-yaml.od.com @10.4.7.11 +short 10.4.7.200
3.浏览器访问k8s-yaml.od.com
4.下载docker镜像并打包上传到harbor仓库
[root@hdss7-200 ~]# docker pull coredns/coredns:1.6.1 [root@hdss7-200 coredns]# docker tag c0f6e815079e harbor.od.com/public/coredns:v1.6.1 [root@hdss7-200 coredns]# docker push harbor.od.com/public/coredns:v1.6.1
5.准备资源配置清单
rbac.yaml
[root@hdss7-200 coredns]# vi rbac.yaml apiversion: v1 kind: serviceaccount metadata: name: coredns namespace: kube-system labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: reconcile --- apiversion: rbac.authorization.k8s.io/v1 kind: clusterrole metadata: labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: reconcile name: system:coredns rules: - apigroups: - "" resources: - endpoints - services - pods - namespaces verbs: - list - watch --- apiversion: rbac.authorization.k8s.io/v1 kind: clusterrolebinding metadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "true" labels: kubernetes.io/bootstrapping: rbac-defaults addonmanager.kubernetes.io/mode: ensureexists name: system:coredns roleref: apigroup: rbac.authorization.k8s.io kind: clusterrole name: system:coredns subjects: - kind: serviceaccount name: coredns namespace: kube-system
cm.yaml
[root@hdss7-200 coredns]# vi cm.yaml apiversion: v1 kind: configmap metadata: name: coredns namespace: kube-system data: corefile: | .:53 { errors log health ready kubernetes cluster.local 192.168.0.0/16 forward . 10.4.7.11 cache 30 loop reload loadbalance }
dp.yaml
[root@hdss7-200 coredns]# vi dp.yaml apiversion: apps/v1 kind: deployment metadata: name: coredns namespace: kube-system labels: k8s-app: coredns kubernetes.io/name: "coredns" spec: replicas: 1 selector: matchlabels: k8s-app: coredns template: metadata: labels: k8s-app: coredns spec: priorityclassname: system-cluster-critical serviceaccountname: coredns containers: - name: coredns image: harbor.od.com/public/coredns:v1.6.1 args: - -conf - /etc/coredns/corefile volumemounts: - name: config-volume mountpath: /etc/coredns ports: - containerport: 53 name: dns protocol: udp - containerport: 53 name: dns-tcp protocol: tcp - containerport: 9153 name: metrics protocol: tcp livenessprobe: httpget: path: /health port: 8080 scheme: http initialdelayseconds: 60 timeoutseconds: 5 successthreshold: 1 failurethreshold: 5 dnspolicy: default volumes: - name: config-volume configmap: name: coredns items: - key: corefile path: corefile
svc.yaml
[root@hdss7-200 coredns]# vi svc.yaml apiversion: v1 kind: service metadata: name: coredns namespace: kube-system labels: k8s-app: coredns kubernetes.io/cluster-service: "true" kubernetes.io/name: "coredns" spec: selector: k8s-app: coredns clusterip: 192.168.0.2 ports: - name: dns port: 53 protocol: udp - name: dns-tcp port: 53 - name: metrics port: 9153 protocol: tcp
6.应用资源配置
[root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/rbac.yaml [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/cm.yaml [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/dp.yaml [root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/coredns/svc.yaml
7.检查创建的资源
[root@hdss7-21 ~]# kubectl get all -n kube-system -o wide
8.验证coredns
[root@hdss7-21 ~]# dig -t a www.baidu.com @192.168.0.2 +short www.a.shifen.com. 14.215.177.38 14.215.177.39
(运维技术交流群:926402931,欢迎大家一起来交流。)
上一篇: Python如何批量生成和调用变量