michelin / ns4kafka

Ns4Kafka brings namespaces on top of Kafka brokers, Kafka Connect and Schema Registry.
Apache License 2.0
73 stars 12 forks source link

question : how to handle "per environment" clusters ? #431

Closed piif closed 1 month ago

piif commented 1 month ago

We handle several clusters, in different environments (dev, staging, production) and we have a question about CI/CD in such context : ns4kafka is able to handle namespaces related to different clusters, but namespace names must be unique. Thus, if I want to deliver "myNamespace" topics in my development cluster, and topics in another "myNamespace" for production cluster, how should I do ? Is it better to use one ns4kafka server per environment, or should I prefix namespaces name by environment name ?

loicgreffier commented 1 month ago

@piif

Thus, if I want to deliver "myNamespace" topics in my development cluster, and topics in another "myNamespace" for production cluster, how should I do

You can manage different contexts using kafkactl:

kafkactl:
  contexts:
    - name: dev
      context:
        api: https://ns4kafka-dev-api.domain.com
        user-token: my_gitlab_token
        namespace: my_namespace
    - name: staging
      context:
        api: https://ns4kafka-dev-api.domain.com
        user-token: my_gitlab_token
        namespace: my_namespace
    - name: production
      context:
        api: https://ns4kafka-prod-api.domain.com
        user-token: my_gitlab_token
        namespace: my_namespace

and set your CI/CD jobs on the desired context before running actions:

kafkactl config use-context dev
kafkactl config use-context staging
kafkactl config use-context production

Additionally, you can use environment variables to configure your jobs in different context: https://github.com/michelin/kafkactl?tab=readme-ov-file#cicd

before_script:
  - export KAFKACTL_CURRENT_NAMESPACE=dev
  - export KAFKACTL_API=https://ns4kafka-dev-api.domain.com
  - export KAFKACTL_USER_TOKEN=${GITLAB_TOKEN}

Is it better to use one ns4kafka server per environment, or should I prefix namespaces name by environment name ?

We use one Ns4Kafka instance per environment, and we also include the environment in the name of the namespace to make it even more clear (e.g., a production namespace would be named pnamespace, a staging namespace would be named snamespace, ...). Using a single instance should work well to get started.

piif commented 1 month ago

Thank you for your answer @loicgreffier As a summary :