Rancher-建立本身的应用商店教程

Rancher(https://rancher.com/)是一个容器管理平台,能够添加、删除容器,查看容器运行状态,也能够批量启动和中止docker compose组成的多个docker组合而成的应用服务,能够支持多台服务节点,支持云服务器,支持多种受权管理方式。Rancher具备Web GUI,操做很方便,入门比较快。node

Rancher Overview

一、快速安装

Rancher自己也是容器服务,快速安装参考:https://rancher.com/quick-start/git

Rancher能够直接启动Docker的镜像,也能够从“应用商店”里快速启动一个应用服务。github

二、应用商店

Rancher“应用商店”实质是docker compose支持的docker image集合,包括官方的应用服务和社区库,都采用git库的方式存储在github中(https://github.com/rancher/community-catalog)。咱们也能够按照相似的格式建立github库,而后将其添加到Rancher的“应用商店”目录列表中。docker

三、自建应用商店

在github.com中建立一个新项目,如rancher-catalog。服务器

  • 而后添加templates目录,本身的应用放到这个目录下面。
  • 以kafka为例,在templates下建立kafka目录。
  • 在kafka目录下建立config.yml,内容为:
name: Apache Kafka
description: |
  Kafka cluster
version: 1.0.0-rancher1
category: Clustering
maintainer: "Raul Sanchez <rawmind@gmail.com>"
minimum_rancher_version: v0.59.0
license: 
projectURL: https://github.com/rawmind0/alpine-kafka
  • 建立一个图标: catalogIcon-kafka.svg
  • 再建立一个版本目录,命名为0,进入目录。
  • 建立文件 rancher-compose.yml,内容为:
.catalog:
  name: Kafka
  version: 0.9.0-rancher1
  description: |
    (Experimental) Apache Kafka cluster.
  minimum_rancher_version: v0.56.0
  maintainer: "Raul Sanchez <rawmind@gmail.com>"
  uuid: kafka-0
  questions:
    - variable: "kafka_scale"
      description: "Number of brokers nodes. Note: Recommended an odd number"
      label: "Broker Nodes:"
      required: true
      default: 3
      type: "int"
    - variable: "kafka_mem"
      description: "Amount of memory to config brokers."
      label: "Broker Memory (mb):"
      required: true
      default: 1024 
      type: "string"
    - variable: "kafka_interval"
      description: "Interval to poll/apply configuration changes. 0 to disable" 
      label: "Broker Interval (s):"
      required: true
      default: 60 
      type: "int"
    - variable: "zk_link"
      description: |
        Choose the Zookeeper service to use. 
        It's really recommended a dedicated zookeeper service just for Kafka.
      label: "Zookeeper stack/service"
      default: "kafka-zk/zk"
      required: true
      type: "service"
broker:
  scale: ${kafka_scale}
  health_check:
    port: 9092
    interval: 5000
    unhealthy_threshold: 3
    request_line: ''
    healthy_threshold: 2
    response_timeout: 5000
  • 建立文件 docker-compose.yml,内容为:
broker:
  tty: true
  image: rawmind/rancher-kafka:0.9.0
  volumes:
  - /opt/kafka/data
  environment:
  - JVMFLAGS=-Xmx${kafka_mem}m -Xms${kafka_mem}m
  - CONFD_INTERVAL=${kafka_interval}
  - ZK_SERVICE=${zk_link}
  external_links:
  - ${zk_link}:zk

按照上面的流程,能够在一个gihub项目中建立多个应用服务。app

如今,进入Rancher,在“添加应用商店”,将github库添加到Rancher的“应用商店”目录列表中。svg

若是没有显示出来,尝试到“系统管理->系统设置”中添加,而后到“应用商店”中点击刷新按钮。ui

四、高级参考

应用商店的详细格式:http://www.javashuo.com/article/p-fiuatifz-dy.htmlspa

自动建立应用商店参考:https://github.com/slashgear/generator-rancher-catalog.net