Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

116
Vistas
How to manage environment variables in Rancher

I want manage environment variables in a stack, then the service can use it. For example: I definition a evn tracker_ip=192.168.0.101, then I want use it in service create.

create service

what should I do

8 months ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

There can be several answers depending on what you are trying to do and how you are deploying your stack.

Using the CLI / Rancher Compose

If you are using the command line, you can just use variable interpolation. Instructions on how to do so can be found in the official documentation:

https://docs.rancher.com/rancher/v1.5/en/cli/variable-interpolation/

Using the Rancher UI / Catalogs

If you want to do it through the Rancher UI, you can do it by creating a template in a catalog and having questions to input your environment variables. More details on how to do so here:

https://docs.rancher.com/rancher/v1.5/en/catalog/private-catalog/

You can define questions in the rancher-compose.yml file like this:

version: '2'
catalog:
  name: My Application
  version: v0.0.1
  questions:
  - variable: TRACKER_IP
    label: Tracker IP address
    required: true
    default: 192.168.0.101
    type: string

You can then push the answers to the environment section of your docker-compose.yml template for use within your image:

version: '2'
services:
  web:
    image: myimage
    ports:
    - 8000
    environment:
      TRACKER_IP: ${TRACKER_IP}
8 months ago · Santiago Trujillo Denunciar

0

There is no way to do exactly what you're asking, because that would allow editing of the variables of running containers and containers are immutable. Environment variables can be defined on services but not defined once on stacks and made available to all services.

Secrets are somewhat like this and can be shared across services, but not edited.

8 months ago · Santiago Trujillo Denunciar

0

Depending on where the tracker_ip is associated, you could also create an external service as part of the stack. The external service essentially just creates a DNS entry in Rancher. So you could then just link your service to the external_tracker service in compose and refer to tracker.

version: '2'
services:
  myservice:
    ...
    link:
      - tracker_service:tracker
...
8 months ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.