美文网首页
八.kubernetes dns 部署

八.kubernetes dns 部署

作者: 竹莲心龙 | 来源:发表于2016-10-28 11:28 被阅读0次

    [在minion节点]

    修改启动服务的参数

    vim start_k8s_minion.sh

    #添加
    dns_ip="172.100.10.1"
    
    #增加--cluster-dns  --cluster-domain
    nohup kubelet --address=0.0.0.0 --port=10250 --v=1 --log_dir=/var/log/k8s/kubelet --hostname_override=$local_ip --api_servers=http://$master_ip:8080 --cluster-dns=$dns_ip --cluster-domain=cluster.local. --logtostderr=false &
    
    重启服务
    ./start_k8s_minion.sh
    
    下载相关镜像,由于国外镜像被墙,所以下载国内第三方镜像
    docker pull chasontang/kubedns-amd64:1.7
    docker pull chasontang/kube-dnsmasq-amd64:1.3
    docker pull chasontang/exechealthz-amd64:1.1
    
    给镜像打标签
    docker tag chasontang/kubedns-amd64:1.7 gcr.io/google_containers/kubedns-amd64:1.7
    docker tag chasontang/kube-dnsmasq-amd64:1.3 gcr.io/google_containers/kube-dnsmasq-amd64:1.3
    docker tag  chasontang/exechealthz-amd64:1.1 gcr.io/google_containers/exechealthz-amd64:1.1
    

    [在master节点]

    准备dns的yaml文件

    dns yaml文件位置: /root/kubernetes/cluster/addons/dns
    文件名称:
    skydns-rc.yaml.in
    skydns-svc.yaml.in

    cd /root/kubernetes/cluster/addons/dns
    cp skydns-rc.yaml.in skydns-svc.yaml.in /root/
    cd /root/
    mv skydns-rc.yaml.in skydns-rc.yaml
    mv skydns-svc.yaml.in skydns-svc.yaml
    
    编辑dns的yaml文件
    vim skydns-rc.yaml
    replicas: {{ pillar['dns_replicas'] }}  
    修改为  
    replicas: 1
    
    args:
    # command = "/kube-dns"
    - --domain={{ pillar['dns_domain'] }}.
    - --dns-port=10053
    {{ pillar['federations_domain_map'] }}
    
    修改为
    
    args:
    # command = "/kube-dns"
    - --domain=cluster.local.
    - --dns-port=10053
    - --kube-master-url=http://10.2.1.11:8080
    
    - -cmd=nslookup kubernetes.default.svc.{{ pillar['dns_domain'] }} 127.0.0.1 >/dev/null && nslookup kubernetes.default.svc.{{ pillar['dns_domain'] }} 127.0.0.1:10053 >/dev/null
    
    修改为
    
    - -cmd=nslookup kubernetes.default.svc.cluster.local. 127.0.0.1 >/dev/null && nslookup kubernetes.default.svc.cluster.local. 127.0.0.1:10053 >/dev/null
    
    vim skydns-svc.yaml
    clusterIP: {{ pillar['dns_server'] }}
    
    修改为
    
    clusterIP: 172.100.10.1
    
    启动rc与svc
    kubectl create -f skydns-rc.yaml
    kubectl create -f skydns-svc.yaml
    
    测试

    vim test.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: test
      namespace: kube-system
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            app: test
        spec:
          containers:
          - name: test
            image: 10.2.3.223:5000/base:v1.2.1_autoserver
            ports:
            - containerPort: 80
              protocol: TCP
            volumeMounts:
            - mountPath: /work
              name: test-volume
          volumes:
            - name: test-volume
              hostPath:
                path: /work/test
    ---
    kind: Service
    apiVersion: v1
    metadata:
      labels:
        app: test
      name: test
      namespace: kube-system
    spec:
      type: NodePort
      ports:
      - port: 80
        targetPort: 30080
      selector:
        app: test
    
    启动
    kubectl create -f test.yaml
    
    测试,登陆的刚刚启动容器
    ssh 172.100.35.3
    
    查看DNS
    cat /etc/resolv.conf 
    search kube-system.svc.cluster.local. svc.cluster.local. cluster.local.
    nameserver 172.100.10.1
    options ndots:5
    
    ping test
    PING test.kube-system.svc.cluster.local (172.100.252.152) 56(84) bytes of data.
    

    可以解析,成功

    参考资料

    相关文章

      网友评论

          本文标题:八.kubernetes dns 部署

          本文链接:https://www.haomeiwen.com/subject/aexeuttx.html