首页 > 解决方案 > 在 Azure 中触发 shell 脚本

问题描述

我在 Azure 中使用运行入口控制器的 Kubernetes 集群。入口控制器通过给定的上下文根路由到不同的服务。

为了添加另一个服务并将其连接到我的入口,我构建了一个简单的 shell 脚本,如下所示:

kubectl apply -f  $1'-svc.yaml'
some script magic here to add a new route in the hello-world-ingress.json
kubectl apply -f 'hello-world-ingress.json'

我在本地机器上测试了脚本,一切都按预期工作。现在我想在 Azure 上使用 HTTP 休息调用来触发脚本。

有谁知道如何做到这一点?到目前为止我知道:

  1. 我需要带有 Kubernetes 的 Azure cli 来运行 kubectl 命令

  2. 我需要一些东西来构建 HTTP 触发器。我尝试使用 AzureFunctions,但无法在 Azure 门户上的 Azure Functions 中安装 Azure cli,也无法在 Docker 容器中安装 Azure cli + Azure Functions。

有谁知道如何在 Azure cli 存在的环境中通过 Azure 中的 HTTP 触发我的 shell 脚本?

标签: bashazurehttptriggerskubernetes

解决方案


在我看来,最简单的方法是设置一个 Azure 实例,kubectl并将 Azure cli 配置为与您的集群通信,并在同一台服务器上设置类似shell2http的东西。例如:

shell2http -export-all-vars /mybash "yourbash.sh"
shell2http -form /apply "kubectl apply -f  $v'-svc.yaml'"
shell2http -export-all-vars /domore "domore.sh"

上面$v是您的部署的名称。


推荐阅读