本章中所使用的镜像为google资源,无法直接使用,本文为自行下载并上传到私有仓库: gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.1 gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.1 gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.1 其实国内也有部分镜像库把gcr.io 替换成gcr.mirrors.ustc.edu.cn就可以下载了

1、修改默认配置文件,本文把所有配置文件贴出来,其实拿官网的对照着改动下即可,关键要和自己环境预定义的一致,其实整个流程很简单,只是过程较多,容易混乱。 配置文件如下: root@ubuntu132:~/dnsyaml# ls kubedns-cm.yaml kubedns-controller.yaml kubedns-sa.yaml kubedns-svc.yaml

root@ubuntu132:~/dnsyaml# cat kubedns-cm.yaml apiVersion: v1 kind: ConfigMap metadata: name: kube-dns namespace: kube-system labels: addonmanager.kubernetes.io/mode: EnsureExists

root@ubuntu132:~/dnsyaml# cat kubedns-controller.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: kube-dns namespace: kube-system labels: k8s-app: kube-dns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile spec:

strategy: rollingUpdate: maxSurge: 10% maxUnavailable: 0 selector: matchLabels: k8s-app: kube-dns template: metadata: labels: k8s-app: kube-dns annotations: scheduler.alpha.kubernetes.io/critical-pod: '' spec: tolerations: - key: "CriticalAddonsOnly" operator: "Exists" volumes: - name: kube-dns-config configMap: name: kube-dns optional: true containers: - name: kubedns image: docker.xxx.com:5000/k8s-dns-kube-dns-amd64:v1.14.1 resources: # TODO: Set memory limits when we've profiled the container for large # 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: 70Mi livenessProbe: httpGet: path: /healthcheck/kubedns port: 10054 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 readinessProbe: 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: 5 args: - --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: TCP volumeMounts: - name: kube-dns-config mountPath: /kube-dns-config - name: dnsmasq image: docker.xxx.com:5000/k8s-dns-dnsmasq-nanny-amd64:v1.14.1 #image为私有仓库中的 livenessProbe: httpGet: path: /healthcheck/dnsmasq port: 10054 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 args: - -v=2 - -logtostderr - -configDir=/etc/k8s/dns/dnsmasq-nanny - -restartDnsmasq=true - -- - -k - --cache-size=1000 - --log-facility=- - --server=/cluster.local/127.0.0.1#10053 - --server=/in-addr.arpa/127.0.0.1#10053 - --server=/ip6.arpa/127.0.0.1#10053 ports: - containerPort: 53 name: dns protocol: UDP - containerPort: 53 name: dns-tcp protocol: TCP # see: https://github.com/kubernetes/kubernetes/issues/29055 for details resources: requests: cpu: 150m memory: 20Mi volumeMounts: - name: kube-dns-config mountPath: /etc/k8s/dns/dnsmasq-nanny - name: sidecar image: docker.xxx.com:5000/k8s-dns-sidecar-amd64:v1.14.1 livenessProbe: httpGet: path: /metrics port: 10054 scheme: HTTP initialDelaySeconds: 60 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 5 args: - --v=2 - --probe=kubedns,127.0.0.1:10053,kubernetes.default.svc.cluster.local,5,A - --probe=dnsmasq,127.0.0.1:53,kubernetes.default.svc.cluster.local,5,A ports: - containerPort: 10054 name: metrics protocol: TCP resources: requests: memory: 20Mi cpu: 10m dnsPolicy: Default # Don't use cluster DNS. serviceAccountName: kube-dns

root@ubuntu132:~/dnsyaml# cat kubedns-sa.yaml apiVersion: v1 kind: ServiceAccount metadata: name: kube-dns namespace: kube-system labels: kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile root@ubuntu132:~/dnsyaml# cat kubedns-svc.yaml apiVersion: v1 kind: Service metadata: name: kube-dns namespace: kube-system labels: k8s-app: kube-dns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "KubeDNS" spec: selector: k8s-app: kube-dns clusterIP: 10.254.0.2 ports:

  • name: dns port: 53 protocol: UDP
  • name: dns-tcp port: 53 protocol: TCP

root@ubuntu132:~/dnsyaml# cat kubedns-svc.yaml apiVersion: v1 kind: Service metadata: name: kube-dns namespace: kube-system labels: k8s-app: kube-dns kubernetes.io/cluster-service: "true" addonmanager.kubernetes.io/mode: Reconcile kubernetes.io/name: "KubeDNS" spec: selector: k8s-app: kube-dns clusterIP: 10.254.0.2 ports:

  • name: dns port: 53 protocol: UDP
  • name: dns-tcp port: 53 protocol: TCP 2、启动以及验证 root# kubectl create -f . 启动所有组件 首先验证kubedns的三个镜像是否正常

验证service是否存在,从下面命令看dns的service ip和预定义的一致,svc正常 root@ubuntu132:~/dnsyaml# kubectl get svc kube-dns --namespace=kube-system NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kube-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-dns NAME READY STATUS RESTARTS AGE kube-dns-2598890466-xc0xd 3/3 Running 37 6d

最后使用node节点部署的验证方法,启动一个nginx或者其他镜像都行,然后进入容器进行kubedns的测试 root@ubuntu132:~/dnsyaml# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-2958629218-44rcm 1/1 Running 0 15h nginx-2958629218-qd5rt 1/1 Running 0 15h root@ubuntu132:~/dnsyaml# kubectl exec -it nginx-2958629218-44rcm /bin/bash 简要ping一下,看是否能够解析 root@nginx-2958629218-44rcm:/# ping kubernetes PING 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 loss root@nginx-2958629218-44rcm:/# ping kube-dns.kube-system.svc.cluster.local PING 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类似,仿照官网的配置文件进行修改。