本文共 6209 字,大约阅读时间需要 20 分钟。
本章中所使用的镜像为google资源,无法直接使用,本文为自行下载并上传到私有仓库:
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.1gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.1gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.1其实国内也有部分镜像库把gcr.io 替换成gcr.mirrors.ustc.edu.cn就可以下载了1、修改默认配置文件,本文把所有配置文件贴出来,其实拿官网的对照着改动下即可,关键要和自己环境预定义的一致,其实整个流程很简单,只是过程较多,容易混乱。
配置文件如下:root@ubuntu132:~/dnsyaml# lskubedns-cm.yaml kubedns-controller.yaml kubedns-sa.yaml kubedns-svc.yamlroot@ubuntu132:~/dnsyaml# cat kubedns-cm.yaml
apiVersion: v1kind: ConfigMapmetadata:name: kube-dnsnamespace: kube-systemlabels:addonmanager.kubernetes.io/mode: EnsureExistsroot@ubuntu132:~/dnsyaml# cat kubedns-controller.yaml
apiVersion: extensions/v1beta1kind: Deploymentmetadata:name: kube-dnsnamespace: kube-systemlabels:k8s-app: kube-dnskubernetes.io/cluster-service: "true"addonmanager.kubernetes.io/mode: Reconcilespec:strategy:
rollingUpdate:maxSurge: 10%maxUnavailable: 0selector:matchLabels:k8s-app: kube-dnstemplate:metadata:labels:k8s-app: kube-dnsannotations:scheduler.alpha.kubernetes.io/critical-pod: ''spec:tolerations:# clusters, then set request = limit to keep this container in # guaranteed class. Currently, this container falls into the # "burstable" category so the kubelet doesn't backoff from restarting it. limits: memory: 170Mi requests: cpu: 100m memory: 70MilivenessProbe: httpGet: path: /healthcheck/kubedns port: 10054 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5readinessProbe: httpGet: path: /readiness port: 8081 scheme: HTTP # we poll on pod startup for the Kubernetes master service and # only setup the /readiness HTTP server once that's available. initialDelaySeconds: 3 timeoutSeconds: 5args:- --domain=cluster.local. 此处的域为事先定义的- --dns-port=10053- --config-dir=/kube-dns-config- --v=2#__PILLAR__FEDERATIONS__DOMAIN__MAP__ #该行注释掉env:- name: PROMETHEUS_PORT value: "10055"ports:- containerPort: 10053 name: dns-local protocol: UDP- containerPort: 10053 name: dns-tcp-local protocol: TCP- containerPort: 10055 name: metrics protocol: TCPvolumeMounts:- name: kube-dns-config mountPath: /kube-dns-config
resources:
requests:cpu: 150mmemory: 20MivolumeMounts:name: sidecar
image: docker.xxx.com:5000/k8s-dns-sidecar-amd64:v1.14.1livenessProbe:httpGet:path: /metricsport: 10054scheme: HTTPinitialDelaySeconds: 60timeoutSeconds: 5successThreshold: 1failureThreshold: 5args:root@ubuntu132:~/dnsyaml# cat kubedns-sa.yaml
apiVersion: v1kind: ServiceAccountmetadata:name: kube-dnsnamespace: kube-systemlabels:kubernetes.io/cluster-service: "true"addonmanager.kubernetes.io/mode: Reconcileroot@ubuntu132:~/dnsyaml# cat kubedns-svc.yaml apiVersion: v1kind: Servicemetadata:name: kube-dnsnamespace: kube-systemlabels:k8s-app: kube-dnskubernetes.io/cluster-service: "true"addonmanager.kubernetes.io/mode: Reconcilekubernetes.io/name: "KubeDNS"spec:selector:k8s-app: kube-dnsclusterIP: 10.254.0.2ports:root@ubuntu132:~/dnsyaml# cat kubedns-svc.yaml
apiVersion: v1kind: Servicemetadata:name: kube-dnsnamespace: kube-systemlabels:k8s-app: kube-dnskubernetes.io/cluster-service: "true"addonmanager.kubernetes.io/mode: Reconcilekubernetes.io/name: "KubeDNS"spec:selector:k8s-app: kube-dnsclusterIP: 10.254.0.2ports:验证service是否存在,从下面命令看dns的service ip和预定义的一致,svc正常
root@ubuntu132:~/dnsyaml# kubectl get svc kube-dns --namespace=kube-system NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEkube-dns 10.254.0.2 <none> 53/UDP,53/TCP 6d验证kubedns 的三个镜像是否正常,如发现pod状态为 2/3之类的,意味着有问题,具体可到相应node上使用docker logs xxxx 查看具体原因。
root@ubuntu132:~/dnsyaml# kubectl get pods --namespace=kube-system -l k8s-app=kube-dnsNAME READY STATUS RESTARTS AGEkube-dns-2598890466-xc0xd 3/3 Running 37 6d最后使用node节点部署的验证方法,启动一个nginx或者其他镜像都行,然后进入容器进行kubedns的测试
root@ubuntu132:~/dnsyaml# kubectl get podsNAME READY STATUS RESTARTS AGEnginx-2958629218-44rcm 1/1 Running 0 15hnginx-2958629218-qd5rt 1/1 Running 0 15hroot@ubuntu132:~/dnsyaml# kubectl exec -it nginx-2958629218-44rcm /bin/bash简要ping一下,看是否能够解析root@nginx-2958629218-44rcm:/# ping kubernetesPING kubernetes.default.svc.cluster.local (10.254.0.1): 56 data bytes^C--- kubernetes.default.svc.cluster.local ping statistics ---2 packets transmitted, 0 packets received, 100% packet lossroot@nginx-2958629218-44rcm:/# ping kube-dns.kube-system.svc.cluster.localPING kube-dns.kube-system.svc.cluster.local (10.254.0.2): 56 data bytes^C--- kube-dns.kube-system.svc.cluster.local ping statistics ---2 packets transmitted, 0 packets received, 100% packet loss至此kubernetes1.6.4版本安装过程到此结束,后续插件dashboard同kubedns类似,仿照官网的配置文件进行修改。
转载于:https://blog.51cto.com/11448017/2048628