Chinaunix首页 | 论坛 | 博客
  • 博客访问: 339287
  • 博文数量: 52
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 577
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-27 14:21
个人简介

知道自己该干嘛,知道自己能干嘛

文章分类

全部博文(52)

文章存档

2019年(1)

2018年(8)

2017年(2)

2016年(11)

2015年(3)

2014年(10)

2013年(17)

我的朋友

分类: 系统运维

2016-12-19 16:55:28


             当搭建完kubernetes后,我们需要使用一个UI平台来对集群进行操作服务, kubernetes 自身就有 dashboard功能
 
               dashboard yaml 如下:
              
  1. [root@kuber-master-141 kube-yaml]# cat kubernetes-dashboard.yaml 

    kind: Deployment
    apiVersion: extensions/v1beta1
    metadata:
      labels:
        app: kubernetes-dashboard
      name: kubernetes-dashboard
      namespace: kube-system
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: kubernetes-dashboard
      template:
        metadata:
          labels:
            app: kubernetes-dashboard
          # Comment the following annotaion if Dashboard must not be deployed on master
          annotations:
            scheduler.alpha.kubernetes.io/tolerations: |
              [
                {
                  "key": "dedicated",
                  "operator": "Equal",
                  "value": "master",
                  "effect": "NoSchedule"
                }
              ]
        spec:
          containers:
          - name: kubernetes-dashboard
            image: docker.io/zhouyan/kubernetes-dashboard-amd64:v1.4.2  // docker hub 拉取相应景象
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 9090
              protocol: TCP
            args:
              # Uncomment the following line to manually specify Kubernetes API server Host
              # If not specified, Dashboard will attempt to auto discover the API server and connect
              # to it. Uncomment only if the default does not work.
              - --apiserver-host=  // 填写自身的apiserver地址端口
            livenessProbe:
              httpGet:
                path: /
                port: 9090
              initialDelaySeconds: 30
              timeoutSeconds: 30
    ---
    kind: Service
    apiVersion: v1
    metadata:
      labels:
        app: kubernetes-dashboard
      name: kubernetes-dashboard
      namespace: kube-system
    spec:
      type: NodePort
      ports:
      - port: 80
        targetPort: 9090
      selector:
        app: kubernetes-dashboard

                  然后通过 master_ip:端口/ui 访问 dashboard, 如本例就是 10.3.1.141:8080/ui


    

                dashboard中也可以看到, po sv 的yaml, 通过edit进行版本更新


               下面我们来介绍一个kube-dns,老版本的kubernetes安装的是 sky-dns,之后kubernetes也推出了自己的dns套件,kube-dns
               简单介绍下kube-dns的套件,以及相应功能。

               kube-dns:  list/watch k8s service api接口
                kube-dnsmasq: 给pod提供DNS解析,并使用自身的DNS缓存功能
               exechealthz: 检测上述2个服务的健康状态

               kube-dns.yml
               
  1. apiVersion: v1
    kind: Service
    metadata:
      name: kube-dns
      namespace: kube-system
      labels:
        k8s-app: kube-dns
        kubernetes.io/cluster-service: "true"
        kubernetes.io/name: "KubeDNS"
    spec:
      selector:
        k8s-app: kube-dns
      clusterIP: 20.254.176.10 // 根据自己的IP段,设置kube-dns 静态IP
      ports:
      - name: dns
        port: 53
        protocol: UDP
      - name: dns-tcp
        port: 53
        protocol: TCP




    ---




    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: kube-dns-v20
      namespace: kube-system
      labels:
        k8s-app: kube-dns
        version: v20
        kubernetes.io/cluster-service: "true"
    spec:
      replicas: 1
      selector:
        k8s-app: kube-dns
        version: v20
      template:
        metadata:
          labels:
            k8s-app: kube-dns
            version: v20
          annotations:
            scheduler.alpha.kubernetes.io/critical-pod: ''
            scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
        spec:
          containers:
          - name: kubedns
            image: docker.io/swqmaven/kubedns-amd64:1.8
            imagePullPolicy: IfNotPresent
            resources:
              limits:
                memory: 170Mi
              requests:
                cpu: 100m
                memory: 70Mi
            livenessProbe:
              httpGet:
                path: /healthz-kubedns
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 60
              timeoutSeconds: 5
              successThreshold: 1
              failureThreshold: 5
            readinessProbe:
              httpGet:
                path: /readiness
                port: 8081
                scheme: HTTP
              initialDelaySeconds: 5
              timeoutSeconds: 5
            args:
            - --domain=cluster.local.
            - --dns-port=10053
            - --kube_master_url= // 根据自身的apiservice地址填写
            ports:
            - containerPort: 10053
              name: dns-local
              protocol: UDP
            - containerPort: 10053
              name: dns-tcp-local
              protocol: TCP
          - name: dnsmasq
            image: docker.io/swqmaven/kube-dnsmasq-amd64:1.4
            imagePullPolicy: IfNotPresent
            livenessProbe:
              httpGet:
                path: /healthz-dnsmasq
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 60
              timeoutSeconds: 5
              successThreshold: 1
              failureThreshold: 5
            args:
            - --cache-size=1000
            - --no-resolv
            - --server=127.0.0.1#10053
            - --log-facility=-
            ports:
            - containerPort: 53
              name: dns
              protocol: UDP
            - containerPort: 53
              name: dns-tcp
              protocol: TCP
          - name: healthz
            image: docker.io/swqmaven/exechealthz-amd64:1.2
            imagePullPolicy: IfNotPresent
            resources:
              limits:
                memory: 50Mi
              requests:
                cpu: 10m
                memory: 50Mi
            args:
            - --cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 >/dev/null
            - --url=/healthz-dnsmasq
            - --cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1:10053 >/dev/null
            - --url=/healthz-kubedns
            - --port=8080
            - --quiet
            ports:
            - containerPort: 8080
              protocol: TCP
          dnsPolicy: Default

        配置kubelet文件,添加dns设置
        [root@kuber-minion-131 data]# grep "ARGS" /etc/kubernetes/kubelet 
        KUBELET_ARGS="--cluster_dns=20.254.176.10 --cluster_domain=cluster.local"
        重启 kubelet.service
        systemctl restart kubelet.service

       新建一个busybox 测试DNS功能
       [root@kuber-minion-131 data]# kubectl get svc --all-namespaces 
        NAMESPACE     NAME                   CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
        default       kubernetes             20.254.0.1              443/TCP         31d
        kube-system   kube-dns               20.254.176.10            53/UDP,53/TCP   24d
        kube-system   kubernetes-dashboard   20.254.176.225   nodes         80/TCP          27d

        [root@kuber-minion-131 data]# kubectl exec busybox -- nslookup kube-dns.kube-system
        Server:    20.254.176.10
        Address 1: 20.254.176.10 kube-dns.kube-system.svc.cluster.local

        Name:      kube-dns.kube-system
        Address 1: 20.254.176.10 kube-dns.kube-system.svc.cluster.local

        [root@kuber-minion-131 data]# kubectl exec busybox -- nslookup kubernetes
        Server:    20.254.176.10
        Address 1: 20.254.176.10 kube-dns.kube-system.svc.cluster.local

        Name:      kubernetes
        Address 1: 20.254.0.1 kubernetes.default.svc.cluster.local

       OK, 今天我们要做的2件事都完成了,dashboard与dns部署, 散会.


                          
                                                                                        Cail_wepiao

     
       参考链接:
           
                     
                    






                             
                                                                                                                                                
阅读(1981) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~