-
Use Airflow broker with redis sentinel개발/Airflow 2023. 1. 9. 11:10
Airflow 를 운영하며, HA에 대한 요건이 발생하여 단일 redis 로 사용중이던걸 redis sentinel 모드로 구성하였다.
8s 클러스터에 Airflow 를 구성하고, k8s 노드 fail 이 발생했을 시 단일 redis 의 container의 fail 이 동반하면 airflow의 기능이 동작하지 않기 때문에, 이를 방지하고자 여러 노드에 master, slave를 분산하여 HA를 보장하고자 하였다.
Airflow was operated, and requirements for HA occurred, so what was being used as a single redis was configured in redis sentinel mode.
Airflow is configured in the k8s cluster, and when a k8s node fails, if a single redis container fails, the airflow function does not work. To prevent this, we tried to ensure HA by distributing master and slave to multiple nodes.기존 Airflow 를 Community version helm chart 를 커스텀하여 사용중이었는데, 기본설정만드로는 sentinel mode의 redis를 사용할 수 없다. externalRedis 의 host 값과 기타 설정들을 세팅하는 방법을 정리해보았다.
I was using the existing Airflow by customizing the Community version helm chart, but I cannot use redis in sentinel mode with the default setting. We have summarized how to set the externalRedis host value and other settings.
1. Broker_url 설정 ( Setting Broker_url )
기존 포스팅에서도 기술하였듯이, redis 로 직접 접속하는것 과 sentinel 로 접속하는것은 url 포멧이 다르다.
As described in the previous post, the url format is different between connecting directly with redis and connecting with Sentinel.
redis://{userid}:{password}@{hostname}:{port}/{database_number}
sentinel://{userid}:{password}@{hostname}:{port}/{database_numer}How to use Airflow celery executor with redis sentinel
Airflow 를 사용할 때 병렬화 처리가 필요하다면, celery executor나 kubernetes excutor의 사용이 필요하다. 이때 queue에 대한 broker 로 rabbitMQ나 redis를 사용할 수 있는데 이 글은 redis를 broker로 사용할때에 대
platib.tistory.com
Airflow community version helm chart에서는 broker_url 을 Values.yaml에 작성한 redis 정보를 이용하여 생성해 전달하게 되는데, sentinel 모드에 대한 설정이 없다. 이를 직접 변경하여야 한다.
In Airflow community version helm chart, broker_url is created and transmitted using redis information written in Values.yaml, but there is no setting for sentinel mode. You must change this yourself.
## bash command which echos the Redis connection stringREDIS_CONNECTION_CMD: {{ `echo -n "redis://$(eval $REDIS_PASSWORD_CMD)${REDIS_HOST}:${REDIS_PORT}/${REDIS_DBNUM}${REDIS_PROPERTIES}"` | b64enc | quote }}{{- end }}
## bash command which echos the Redis connection stringREDIS_CONNECTION_CMD: {{ `echo -n "sentinel://$(eval $REDIS_PASSWORD_CMD)${REDIS_HOST}:${REDIS_PORT}/${REDIS_DBNUM}${REDIS_PROPERTIES}"` | b64enc | quote }}{{- end }}
bitnami redis helm chart를 이용해 설치하여, redis sentinel 에 대한 headless service가 구성되어있기 때문에 하나의 주소만 넣었지만, sentinel 의 url들을 ; 로 구분하여 여러개 입력해도 된다.
Since it was installed using bitnami redis helm chart and the headless service for redis sentinel is configured, only one address was put in, but the urls of sentinel ; You can enter multiple entries by separating them with .
2. Celery_broker_transport_option 설정 (Setting Celery_broker_transport_option)
sentinel 로 접속을 시도 했기 때문에, master를 찾아가기 위해서 redis 설치시 설정한 master name을 전달해야한다.
Values.yaml 에 config 설정으로 추가가능하다.
Since you tried to connect with sentinel, you need to pass the master name set when installing redis to find the master.
It can be added as a config setting in Values.yaml .config:
AIRFLOW__CELERY_BROKER_TRANSPORT_OPTIONS__MASTER_NAME: mymaster3. Sentinel_kwargs 설정 (Setting Sentinel_kwargs)
redis에 authentification 설정이 되어있다면, 이를 sentinel로 전달해야한다. broker url 포멧에 auth 정보가 포함되어있지만, celery bug로 auth 설정이 추가적으로 되어있지 않으면 다음과 같이 master를 찾을 수 없다는 오류가 발생한다.
If redis has authentication set up, you need to pass it to sentinel. If auth information is included in the broker url format, but the auth setting is not additionally set due to a celery bug, the following error occurs saying that the master cannot be found.
[2022-12-12 15:46:10,840: ERROR/MainProcess] consumer: Cannot connect to sentinel://xxx:26379//: No master found for 'xxx'. Trying again in 32.00 seconds... (16/100)
Celery 로 직접 sentinel_kwargs를 전달해주어야 하는데, Airflow configuration (AIRFLOW__CELERY_BROKER_TRANSPORT_OPTIONS__SENTINEL_KWARGS)을 통해서 sentinel_kwargs는 전달이 되지 않는다.
Sending sentinel_kwargs directly to Celery is necessary, but sending sentinel_kwargs is not possible through Airflow configuration (AIRFLOW__CELERY_BROKER_TRANSPORT_OPTIONS_SENTINEL_KWARGS).
airflow.exceptions.AirflowConfigException: Failed to convert value automatically. Please check "sentinel_kwargs" key in "celery_broker_transport_options" section is set.
custom_celery_config 설정을통해 아래 configuration을 전달해줘야 한다. 이때 custom celery로 celery configuration을 덮어쓰기 때문에 airflow configuration으로 전달가능한(AIRFLOW__CELERY_BROKER_TRANSPORT_OPTIONS__MASTER_NAME) master name 역시 함께 넣어주도록한다.
The following configuration must be delivered through the custom_celery_config setting. At this time, since the celery configuration is overwritten by custom celery, the master name that can be transferred to the airflow configuration (AIRFLOW__CELERY_BROKER_TRANSPORT_OPTIONS__MASTER_NAME) should also be included.
master_name: "mymaster"
sentinel_kwargs : { 'password': "password" }Custom_celery_config 설정은 아래 포스팅을 참고해주세요.
Please refer to the post below for the Custom_celery_config setting.
Airflow 의 Celery executor 의 custom configuration
Airflow의 executor 를 celery 로 사용중에 configuration 을 수정해야할 경우가 있다. 예를 들어, database engine options 를 추가한다던지.. 이번 case는 celery의 result_backend 로 사용하는 mysql 과의 연결 관리를 위
platib.tistory.com
참고문헌.
Configuration Reference — Airflow Documentation
airflow.apache.org
Using Redis — Celery 5.2.7 documentation
This document describes the current stable version of Celery (5.2). For development docs, go here. Using Redis Installation For the Redis support you have to install additional dependencies. You can install both Celery and these dependencies in one go usin
docs.celeryq.dev
'개발 > Airflow' 카테고리의 다른 글
Airflow 의 Celery executor 의 custom configuration (0) 2023.01.09 How to use Airflow celery executor with redis sentinel (0) 2021.05.21