Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create a Rancher-based Catalog for a Keepalived service

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Keepalived's role is to detect the status of the server. If a web server crashes or fails, Keepalived will detect it and remove the failed server from the system. When the server works normally, Keepalived will automatically add the server to the server group. These tasks are all automatically completed without manual intervention. All that needs to be done manually is to repair the failed server.

First, let's briefly explain Keepalived's startup scripts and configuration files: keepalived.sh is the core script used to start the service, and keepalived.conf file is the configuration file of the service. For Keepalived, several important parameters we need to care about are as follows:

Virtual IP addresses and their masks

The port on which VRRP listens (i.e. which port HA does health check)

VRRP is published based on which NIC interface.

I believe Rancher's official manual has detailed instructions on how to make a Catalog, but there are still some friends who read the Catalog section of Rancher manual and are confused about how to make an application Catalog.

(link to official manual here): docs.rancher.com/rancher/latest/en/catalog/private-catalog/

Combined with Keepalived, let's see how the Catalog is created.

First, you need to create a project on github or on your own gitlab, which is OK as long as it can be handled properly by the git clone command. For example, the project structure we created on github is shown below:

The templates directory corresponds to the Catalog of our Rancher Cattle environment. Kubernetes-templates and swarm-templates, as well as mesos-templates, correspond to templates for different environments. Going into the templates, we can see the template names corresponding to those on the Rancher Catalog page.

If we go into the Keepalived folder, it will be easy to understand the official documentation for Catalog compilation process guidance.

This catalogIcon-keepalived.png graph is exactly what we see it to be:

The config.yml file is the basic description of the catalog; the 0 directory refers to the first version, so the next time you issue a new version of the Catalog, you need to create another 1 directory.

Each version folder such as 0 contains three files.

This is exactly what we need to create a Stack: docker-compose.yml and rancher-compose.yml, and of course a README.md file to describe Stack in detail.

For this Keepalived, its docker-compose.yml is particularly simple:

But p_w_picpath here you need to spend a little effort, you need to handle the correct environment variables, parameters passed. Otherwise, once there is a problem with the parameter transmission we saw in Rancher Catalog, the service will definitely not run. The Dockerfile used to make p_w_picpath contains the following contents:

How are these custom configuration options implemented?

The official documentation tells us that it is defined in the rancher-compose file. Take our Keepalived service as an example:

The rancher-compse.yml file defines a number of UI object attributes (e.g. variable names, data types, required options, labels, descriptions, defaults, etc.) in the question section, and the answers.txt file gives the default status of these items accordingly.

For the actual Keepalived service, we can see that the docker-compose.yml file defines four environment variables (VIRTUAL_IP, CHECK_PORT, INTERFACE, NETMASK_BIT) and a constant VRID:

The above four environment variables can be called directly by the container shell. For example, these four variables are called in the keepalived.sh script, and the specific assignment of these four variables is completed in the Catalog production stage. Its value is output by the variables in the rancher-compose.yml file, namely:

In particular, the keepalived.sh script needs to read the parameters in the keepalived.conf file during runtime, especially the above four parameters, so since the keepalived.conf file must be written in Dockerfile before p_w_picpaths are generated, they must be variables in Dockerfile, and after the container runs,keepalive.sh needs to assign variables before running, and these values are exactly what the user fills in. Let's see how keepalived.sh works.

By combining the key four-sentence sed directive with a regular expression:

The keepalived.sh script successfully replaces variable arguments in the keepalived.conf configuration file for the container runtime with constants (which are passed into the Linux Shell environment by the container environment variables).

Such a complete Catalog creation process, including how to handle environment variables and custom parameters, is explained clearly. According to this idea, we can easily create various application templates to realize Rancher's one-click deployment function.

Source: Rancher Labs

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report