首页 > 解决方案 > 如何在气流的 KubernetesPodOperator 中使用 --privileged 运行 docker 映像

问题描述

如何使用在 GCP 中的 Container Registry 中使用 Running this docker runlocal 进行私有映像工作正常:--privileged

docker run -it --privileged --entrypoint /bin/bash ${GKE_APP}

我跟着这个,但错误仍然存​​在。

这是我的 DAG:

def process_backup_data(data_to_backup):

    secret_file = Secret('volume', '/etc/secrets', 'my-secret')

    task_env_vars = {'GOOGLE_APPLICATION_CREDENTIALS': "/etc/secrets/my-sa.json}
    

    security_context = {
                        'privileged': True,
                        'allow_privilege_escalation': True,
                        'capabilities': {'add': ['SYS_ADMIN']}
                       }

    return KubernetesPodOperator(image="asia.gcr.io/my-image:latest",
                         env_vars=task_env_vars,
                         cmds=["sh", "run-vpn-script.sh"],
                         arguments=[data_to_backup],
                         labels={"project": "my-project"},
                         name="my-project-backup-datasets",
                         task_id=f"backup_{task_id}",
                         dag=dag,
                         secrets=[secret_file],
                         image_pull_policy='Always',
                         security_context=security_context # HERE
                         )

标签: dockerkubernetesairflowkubernetes-podkubernetespodoperator

解决方案


您是否检查过您是否缺少某种能力?

我在您发布的示例中看到他们还将其添加到security_context

'capabilities': {'add': ['SYS_ADMIN']}

推荐阅读