关注微信公众号
第一手干货与资讯
加入官方微信群
获取免费技术支持
If you use Rancher 1.6, you probably already know about Rancher Catalog, which lets your Rancher system users create and share application templates without the need for any technical knowledge about the applications. In this tutorial, you’ll learn how to:
You can configure Rancher Catalog with different catalog repositories (repos) to get distinct templates. A catalog repo is just a Git repo with a specific structure. By default, Rancher Catalog includes templates for two public catalog repos:
Rancher enables these catalogs by default, but the admin can disable them on the Admin > Settings page.
One of the coolest features inside Rancher Catalog is the ability to generate and add your own catalog repos to your Rancher system.
This feature is especially useful when you want to:
There are two different kinds of Rancher Catalog repos:
As a basic example, let’s suppose you already have your docker-compose and rancher-compose files. For example:
docker-compose
rancher-compose
docker-compose.yml
version: '2' services: test: image: rawmind/web-test tty: true labels: io.rancher.container.hostname_override: container_name io.rancher.scheduler.affinity:container_label_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} lb: image: rancher/lb-service-haproxy:v0.7.6 ports: - 8080:8080/tcp labels: io.rancher.container.agent.role: environmentAdmin io.rancher.container.create_agent: 'true'
rancher-compose.yml
version: '2' services: test: scale: 2 retain_ip: true start_on_create: true health_check: healthy_threshold: 2 response_timeout: 2000 port: 8080 unhealthy_threshold: 3 initializing_timeout: 60000 interval: 2000 strategy: recreate request_line: GET "/" "HTTP/1.0" lb: scale: 1 start_on_create: true lb_config: certs: [] port_rules: - hostname: '' priority: 1 protocol: http service: test source_port: 8080 target_port: 8080 health_check: healthy_threshold: 2 response_timeout: 2000 port: 42 unhealthy_threshold: 3 initializing_timeout: 60000 interval: 2000 reinitializing_timeout: 60000
Create a package structure inside each folder type:
Create a config.yml file to describe the package:
config.yml
name: # The name of the Catalog entry description: | # A description of the Catalog entry version: #The default version of the package to use (must match any folder in the rancher-compose version) category: # The category to use when searching for Catalog entries maintainer: # The maintainer of the Catalog entry license: # The license projectURL: # The URL related to the Catalog entry
To display an icon for the Catalog entry, create an image file prefixed with “catalogIcon-,\” such as catalogIcon-myservice.svg. The preferred image format is SVG, but PNG and JPG are allowed.
Create a folder for every package version. The package name has to be a number. Use \“0\” for the first version, “1” for the second version, and so on. Inside every version folder, you need to add these files:
docker-compose.yml — Set your questions variable values, if needed.
questions
version: '2' services: test: image: rawmind/web-test tty: true labels: io.rancher.container.hostname_override: container_name io.rancher.scheduler.affinity:container_label_ne: io.rancher.stack_service.name=$${stack_name}/$${service_name} lb: image: rancher/lb-service-haproxy:v0.7.6 ports: - ${PUBLISH_PORT}:${PUBLISH_PORT}/tcp labels: io.rancher.container.agent.role: environmentAdmin io.rancher.container.create_agent: ‘true'
rancher-compose.yml — Add a catalog section and questions to this file.
catalog
version: '2' catalog: name: "myservice" version: “0.1" description: "Package example to show private repo" questions: - variable: "PUBLISH_PORT" label: "Publish port" description: | Select port to publish service required: true default: "8080" type: int services: test: scale: 2 retain_ip: true start_on_create: true health_check: healthy_threshold: 2 response_timeout: 2000 port: 8080 unhealthy_threshold: 3 initializing_timeout: 60000 interval: 2000 strategy: recreate request_line: GET "/" "HTTP/1.0" lb: scale: 1 start_on_create: true lb_config: certs: [] port_rules: - hostname: '' priority: 1 protocol: http service: test source_port: 8080 target_port: 8080 health_check: healthy_threshold: 2 response_timeout: 2000 port: 42 unhealthy_threshold: 3 initializing_timeout: 60000 interval: 2000 reinitializing_timeout: 60000
README.md — Optionally, we recommend adding this file to describe how the package works.
Your Git repo folder structure should look like this:
templates |_ myservice |_ config.yml |_ catalogIcon-myservice.svg |_ 0 |_ docker-compose.yml |_ rancher-compose.yml |_ README.md
Add, commit, and push your files into your Git repo.
To update to a new package version, create a folder with the next version number inside your catalog folder, and then add new docker-compose and rancher-compose files.
Congrats! You created your first private catalog.
Once you’ve created your first catalog repo, you can use or share it. To use it, just add your < GIT_REPO > URL and < GIT_BRANCH > to your Rancher system as a catalog kind:
Rancher Server clones the Git repo automatically, and you can access your catalog repo packages from the Catalog > < NAME > menu.
This blog entry taught you how to create a private catalog repo to provide templates for your users or customers. For more information, see our Catalog docs. You can also read our best practices for Catalog packages on GitHub.
Raul Sanchez Liebana is a DevOps Lead at Rancher Labs.