最近響應(yīng)國家政策晌端,在家實(shí)屬無聊捅暴,嘗試用k8s部署一下DNS系統(tǒng),記錄一下咧纠!
提前準(zhǔn)備了三個(gè)docker鏡像蓬痒,根域名解析鏡像,頂級域名解析鏡像以及本地域名解析鏡像
一漆羔、創(chuàng)建控制器,這里采用Deployment
1.根域名解析deployment.yaml文件:
apiVersion: apps/v1
kind:? Deployment
metadata:
? name:? bind-deployment #deployment名稱
spec:
? replicas: 1 #為了方便梧奢,副本數(shù)暫時(shí)設(shè)置為1
? selector:
? ? matchLabels: #下面引用兩個(gè)標(biāo)簽,方便創(chuàng)建service微服務(wù)
? ? ? app: bind?
? ? ? type: root
? template:
? ? metadata:
? ? ? labels:
? ? ? ? app: bind
? ? ? ? type: root
? ? spec:
? ? ? containers:
? ? ? - name: bind #容器名
? ? ? ? image: www.jieyinglei.com/library/bind:latest
? ? ? ? ports:
? ? ? ? - containerPort: 53 #打開容器53端口
? ? ? ? ? protocol: UDP #端口類型
? ? ? ? securityContext:
? ? ? ? ? privileged: true #打開privileged權(quán)限
2.頂級域名解析deployment.yaml文件:
apiVersion: apps/v1
kind:? Deployment
metadata:
? name:? com-bind-deployment
spec:
? replicas: 3? #副本數(shù)量設(shè)置為3
? selector:
? ? matchLabels:
? ? ? app: bind
? ? ? type: com
? template:
? ? metadata:
? ? ? labels:
? ? ? ? app: bind
? ? ? ? type: com
? ? spec:
? ? ? containers:
? ? ? - name: bind
? ? ? ? image: www.jieyinglei.com/library/com-dns:latest
? ? ? ? ports:
? ? ? ? - containerPort: 53
? ? ? ? ? protocol: UDP
? ? ? ? securityContext:
? ? ? ? ? privileged: true
3.本地域名解析deployment.yaml文件:
apiVersion: apps/v1
kind:? Deployment
metadata:
? name:? local-bind-deployment
spec:
? replicas: 1
? selector:
? ? matchLabels:
? ? ? app: bind
? ? ? type: local
? template:
? ? metadata:
? ? ? labels:
? ? ? ? app: bind
? ? ? ? type: local
? ? spec:
? ? ? containers:
? ? ? - name: local-bind
? ? ? ? image: www.jieyinglei.com/library/local-dns:latest
? ? ? ? ports:
? ? ? ? - containerPort: 53
? ? ? ? ? protocol: UDP
? ? ? ? securityContext:
? ? ? ? ? privileged: true
4.用kubectl create -f? 來創(chuàng)建上面三個(gè)deployment
kubectl get deployment查看一下演痒,看到下面這樣就完成一小步啦
kubectl get pod 查看創(chuàng)建好的pod :
如果有哪些pod 的STATUS是沒有Running的亲轨,表明該pod還沒有準(zhǔn)備好,可以用下面命令去查看一下詳細(xì)信息:
kubectl describe pod podName(pod 也可以換成其他資源嫡霞,如deployment瓶埋、svc等)
5.最后用dig去查看一下bind是否正常返回
到這里就可以進(jìn)一步創(chuàng)建svc啦
二、創(chuàng)建service
1.根域名解析svc.yaml文件:
apiVersion: v1
kind: Service
metadata:
? name: bind? ????#svc名稱
? namespace: default? ? ? ? #默認(rèn)名稱空間
spec:
? type: ClusterIP
? selector:? ?#這里選擇哪些pod作為代理對象,通過訪問svc养筒,會(huì)將請求分發(fā)到每一個(gè)pod中
? ? app: bind? ?
? ? type: root
? ports:
? - name: bind
? ? port: 53
? ? targetPort: 53
? ? protocol: UDP
2.頂級域名解析svc.yaml文件:
apiVersion: v1
kind: Service
metadata:
? name: com-bind
? namespace: default
spec:
? type: ClusterIP
? selector:
? ? app: bind
? ? type: com
? ports:
? - name: bind
? ? port: 53
? ? targetPort: 53
? ? protocol: UDP
3.本地域名解析svc.yaml文件:
apiVersion: v1
kind: Service
metadata:
? name: local-bind
? namespace: default
spec:
? type: ClusterIP
? selector:
? ? app: bind
? ? type: local
? ports:
? - name: bind
? ? port: 53
? ? targetPort: 53
? ? protocol: UDP
4.用kubectl create -f? 來創(chuàng)建上面三個(gè)svc
查看:kubectl get svc
三曾撤、修改根地名解析,頂級域名解析晕粪,本地域名解析配置文件挤悉,查看效果
這里我對k8s和bind都是初步了解而已,所以我選擇進(jìn)入pod里面一個(gè)個(gè)修改巫湘。装悲。。尚氛。诀诊。
前面已經(jīng)把頂級域名解析的pod副本數(shù)設(shè)置為3,所以這里可以讓每一個(gè)pod對同一個(gè)域名做出不同的解析阅嘶。
第二個(gè)解析到2.2.2.2 属瓣,第三個(gè)解析到3.3.3.3
四、效果
第一次解析:
第二次解析:
第三次解析:
end!!!