美文网首页自动化程序员
手把手教你构建 Kubernetes 1.8 + Flannel

手把手教你构建 Kubernetes 1.8 + Flannel

作者: 51reboot | 来源:发表于2018-01-04 14:07 被阅读300次

    怕大家等不及,我们接着昨天的分享继续

    四.Heapster+InfluxDB+Grafana

    注意: 时间不同步 Grafana 查看里面不会有数据
    项目地址:
    https://github.com/kubernetes/heapster.git

    [root@node1 ~]# git clone https://github.com/kubernetes/heapster.git
    [root@node1 ~]# cd heapster/deploy/kube-config/influxdb/
    [root@node1 ~]# ls
    grafana.yaml  heapster.yaml  influxdb.yaml
    

    我们需要创建三个容器,修改镜像地址为阿里云镜像地址,否则无法 pull 下来镜像
    1.Influxdb
    [root@node1 influxdb]# vi influxdb.yaml#镜像地址修改为深圳镜像地址(如果下载不下来,分享完会附带资料,每个节点都要导入镜像)image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/heapster-influxdb-amd64:v1.3.3
    [root@node1 influxdb]# kubectl  create -f  influxdb.yaml
     kubectl get pods --namespace=kube-system -o wide
    

    2.Grafana

    [root@node1 influxdb]# vi   grafana.yaml
    #镜像地址修改为深圳镜像地址(如果下载不下来,分享完会附带资料,每个节点都要导入镜像)
    image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/heapster-grafana-amd64:v4.4.3
    [root@node1 influxdb]# kubectl  create -f  grafana.yaml
    

    3.Heapster

    [root@node1 influxdb]# vi heapster.yaml 
    #镜像地址修改为深圳镜像地址(如果下载不下来,本文档会附带,每个节点都要导入镜像)
    image: registry.cn-hangzhou.aliyuncs.com/outman_google_containers/heapster-amd64:v1.4.0
    - --source=kubernetes:http://192.168.31.221:8080?inClusterConfig=false&useServiceAccount=true&auth=
    
    [root@node1 influxdb]# kubectl  create -f  heapster.yaml
    

    4.查看三个容器的状态

    5.访问 dashboard 进行测试

    http://192.168.0.221:8080/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy/



    http://192.168.31.221:8080/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy/?orgId=1

    五.使用glusterfs做持久化存储

    1. 先安装 gluster 源

    yum install centos-release-gluster -y
    

    2. 安装 glusterfs 组件

    yum install -y glusterfs glusterfs-server glusterfs-fuse glust
    

    3.创建 glusterfs 目录

    mkdir /opt/glusterd
    

    4.修改 glusterd 目录

    sed -i 's/var\/lib/opt/g' /etc/glusterfs/glusterd.vol
    

    5.启动 glusterfs

    systemctl start glusterd.service  && systemctl enable glusterd.service
    

    6.配置 glusterfs

    [root@node1 k8s]# vi /etc/hosts #每个节点都要配hosts
    

    7.开放端⼝

    iptables -I INPUT -p tcp --dport 24007 -j ACCEPT
    

    8.创建存储⽬录

    mkdir /opt/gfs_data
    

    9.添加节点到集群

    # 执⾏操作的本机不需要probe 本机
    gluster peer probe node2.example.com
    gluster peer probe node3.example.com
    

    10.查看集群状态
    gluster peer status

    11.配置 volume
    GlusterFS 中的 volume 的模式有很多中,包括以下⼏种:
    分布卷(默认模式):即DHT, 也叫 分布卷: 将⽂件已hash算法随机分布到 ⼀台服务器节点中存储。
    复制模式:即 AFR, 创建 volume 时带 replica x 数量: 将⽂件复制到 replica x 个节点中。
    条带模式:即 Striped, 创建 volume 时带 stripe x 数量: 将⽂件切割成数据块,分别存储到 stripe x 个节点中 ( 类似raid 0 )。
    分布式条带模式:最少需要4台服务器才能创建。 创建 volume 时 stripe 2 server = 4 个节点: 是 DHT 与 Striped 的组合型。
    分布式复制模式:最少需要4台服务器才能创建。 创建 volume 时 replica 2 server = 4 个节点:是 DHT 与 AFR 的组合型。
    条带复制卷模式:最少需要4台服务器才能创建。 创建 volume 时stripe 2 replica 2 server = 4 个节点: 是 Striped 与 AFR 的组合型。
    三种模式混合: ⾄少需要8台 服务器才能创建。 stripe 2 replica 2 ,每4个节点 组成⼀个 组。

    [root@node1 k8s]#   gluster volume create  k8s-volume  node1.example.com:/opt/gfs_data/ node2.example.com:/opt/gfs_data/ node3.example.com:/opt/gfs_data/    force
    

    12.查看 volume 状态
    [root@node1 k8s]# gluster volume info


    13.启动 分布卷
    [root@node1 k8s]# gluster volume start k8s-volume
    14.挂载测试
    [root@node2 ~]# mount -t glusterfs node1.example.com:k8s-volume /media/

    15.配置 endpoints
    https://github.com/kubernetes/kubernetes/blob/master/examples/volumes/glusterfs/glusterfs-endpoints.json
    {
      "kind": "Endpoints",
      "apiVersion": "v1",
      "metadata": {
        "name": "glusterfs-cluster"
      },
      "subsets": [
        {
          "addresses": [
            {
              "ip": "192.168.0.221"
            }
          ],
          "ports": [
            {
              "port": 1990
            }
          ]
        },
        {
          "addresses": [
            {
              "ip": "192.168.0.222"
            }
          ],
          "ports": [
            {
              "port": 1990
            }
          ]
        }
      ]
    }
    [root@node1 ~]# kubectl  create -f glusterfs-endpoints.json
    

    查看 endpoints 信息


    创建服务:

    https://github.com/kubernetes/kubernetes/blob/master/examples/volumes/glusterfs/glusterfs-service.json

    {
      "kind": "Service",
      "apiVersion": "v1",
      "metadata": {
        "name": "glusterfs-cluster"
      },
      "spec": {
        "ports": [
          {"port": 1990}
        ]
      }
    }
    [root@node1 ~]# kubectl  create -f glusterfs-service.json 
    [root@node1 ~]# kubectl get svc
    

    查看 endpoints 信息


    16.创建测试 pod
    https://github.com/kubernetes/kubernetes/blob/master/examples/volumes/glusterfs/glusterfs-pod.json

    "path": "k8s-volume"                #这里改为,gfs卷名字
    [root@node1 k8s]# kubectl  create -f glusterfs-pod.json
    
    [root@node1 k8s]#  kubectl exec glusterfs  mount | grep gluster
    

    未完待续.......

    相关文章

      网友评论

        本文标题:手把手教你构建 Kubernetes 1.8 + Flannel

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