码迷,mamicode.com
首页 > 其他好文 > 详细

k8s部署dns

时间:2016-08-22 17:50:15      阅读:456      评论:0      收藏:0      [点我收藏+]

标签:

硬件环境:

两台虚拟机,

10.10.20.203 部署docker、etcd、flannel、kube-apiserver、kube-controller-manager、kube-scheduler

10.10.20.206 部署docker、flannel、kubelet、kube-proxy

软件环境:

kubernetes:1.3.3

DNS-etcd:index.tenxcloud.com/google_containers/etcd:2.2.5

kube2sky:index.tenxcloud.com/google_containers/kube2sky:1.15

skyDNS:index.tenxcloud.com/google_containers/skydns:2015-10-13-8c72f8c

1、创建dns-rc.yaml

apiVersion: v1
kind: ReplicationController
metadata:
  name: dns-rc-test
  labels:
    k8s-app: dns
    version: v8
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 1
  selector:
    k8s-app: dns
    version: v8
    kubernetes.io/cluster-service: "true"
  template:
    metadata:
      labels:
        k8s-app: dns
        version: v8
        kubernetes.io/cluster-service: "true"
    spec:
      containers:
      - name: etcd
        image: 10.10.20.202/library/etcd:2.2.5
        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: 10.10.20.202/library/kube2sky:1.15
        args:
        - --kube-master_url=http://10.10.20.203:8080  #改换实际的master地址
        - --domain=cluster.local
      - name: skydns
        image: 10.10.20.202/library/skydns:2015-10-13
        args:
        - -machines=http://127.0.0.1:4001
        - -addr=0.0.0.0:53
        - -domain=cluster.local
        ports:
        - containerPort: 53
          name: dns-udp
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
      volumes:
      - name: etcd-storage
        emptyDir: {}
      dnsPolicy: Default

2、创建dns-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: dns-svc-test
  labels:
    k8s-app: dns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "DNStest"
spec:
  selector:
    k8s-app: dns
  clusterIP: 10.254.159.10   #在service-cluster-ip-range范围取一个值
  ports:
  - name: dns-udp
    port: 53
    protocol: UDP
  - name: dns-tcp
    port: 53
    protocol: TCP

3、部署dns

kubectl create -f /root/k8s/dns/dns-rc.yaml
kubectl create -f /root/k8s/dns/dns-service.yaml

4、在kubelet的启动脚本中增加cluster-dns=10.254.159.10和cluster-domain=cluster.local,如下,并重启kubelet。

kubelet --logtostderr=true --v=0 --address=0.0.0.0 --api-servers=http://10.10.20.203:8080 \
--pod-infra-container-image=index.tenxcloud.com/google_containers/pause-amd64:3.0 --cluster-dns=10.254.159.10 --cluster-domain=cluster.local >> /var/log/kubelet.log 2>&1 &

5、进入一个pod中执行域名解析和telnet指令,验证域名是否可用

[root@k8s-master bin]# kubectl get service
NAME                 CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
dns-svc-test         10.254.159.10    <none>        53/UDP,53/TCP   4d
emp-authc-service    10.254.64.191    <nodes>       11111/TCP       40m
emp-portal-service   10.254.20.196    <nodes>       8080/TCP        39m
kubernetes           10.254.0.1       <none>        443/TCP         10d
postgresql-service   10.254.161.247   <nodes>       5432/TCP        2h
redis-service        10.254.160.1     <nodes>       6379/TCP        1h
zookeeper-service    10.254.229.137   <nodes>       2181/TCP        2h
[root@k8s-master bin]# kubectl exec centos-master-fy8r4 -i -t -- bash -il
[root@centos-master-fy8r4 /]# nslookup postgresql-service
Server:        10.254.159.10
Address:    10.254.159.10#53

Name:    postgresql-service.default.svc.cluster.local
Address: 10.254.161.247

[root@centos-master-fy8r4 /]# telnet postgresql-service 5432
Trying 10.254.161.247...
Connected to postgresql-service.
Escape character is ^].

 

k8s部署dns

标签:

原文地址:http://www.cnblogs.com/puroc/p/5796179.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!