Argo Eventsを別のNamespaceで動かす
Argo EventsでGatewayやSensorをArgo EventsがデプロイされているNamespace以外のNamespaceにデプロイして動かすことをしてみようと思います。
はじめに
今回はVagrant上に立てたMinikubeを使って作業していきます。
前もってMinikubeをstartしておきます。
GitHub - kkasai/vagrant-minikube
Argo Workflowの構築
まず、Argo Workflowを構築していきます。
以下ページにある方法で構築してもいいのですが、折角なのでHelmを使って構築してみようと思います。
argo/demo.md at v2.2.1 · argoproj/argo · GitHub
Helmのインストール
以下ページを参考にHelmのインストールをします。
https://helm.sh/docs/using_helm/#installing-the-helm-client
$ curl -sSLO https://storage.googleapis.com/kubernetes-helm/helm-v2.13.1-linux-amd64.tar.gz $ tar -zxvf helm-v2.13.1-linux-amd64.tar.gz $ mv linux-amd64/helm /usr/local/bin/helm $ helm init
helm init
コマンドを打つことでTillerがk8sにデプロイされます。
このTillerがk8sにインストールするようです。
install
Helmを使ってArgo Workflowを構築していきます。
# ArgoのHelmリポジトリを追加 $ helm repo add argo https://argoproj.github.io/argo-helm # Argo Workflowをインストール $ helm install argo/argo --name argo --set images.tag=v2.2.1,ui.serviceType=LoadBalancer
サンプルを動かしてみる
Argoコマンドをインストールして、サンプルを動かしてみます。
argo/demo.md at v2.2.1 · argoproj/argo · GitHub
$ curl -sSL -o /usr/local/bin/argo https://github.com/argoproj/argo/releases/download/v2.2.1/argo-linux-amd64 $ chmod +x /usr/local/bin/argo $ argo submit --watch https://raw.githubusercontent.com/argoproj/argo/v2.2.1/examples/hello-world.yaml $ argo list NAME STATUS AGE DURATION hello-world-cjcnc Succeeded 2m 2m $ argo logs hello-world-cjcnc _____________ < hello world > ------------- \ \ \ ## . ## ## ## == ## ## ## ## === /""""""""""""""""___/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ \______ o __/ \ \ __/ \____\______/
折角なのでブラウザ上からもみてます。
以下コマンドを実行して、
$ kubectl proxy --address 0.0.0.0
以下のURLにアクセスしてみると先ほど実行されたWorkflowがみられると思います。
http://127.0.0.1:8001/api/v1/namespaces/default/services/http:argo-ui:/proxy/
Argo Eventsの構築
続いてArgo Eventsを構築していきます。
argo-events/README.md at v.0.9 · argoproj/argo-events · GitHub
install
$ helm install argo/argo-events --name argo-events --set sensorController.tag=v0.9,gatewayController.tag=v0.9,singleNamespace=false
singleNamespace=false
を設定することにより、Argo EventsがいるNamespaceだけではなく、ほかのNamespaceにあるGateway、Sensorを使うことができます。
GatewayやSensorなどの定義
Argo Eventsに必要なものの定義をしていきます。
まずは権限周り。
新しいNamespace用にService Accountを用意して、Argo Eventsをインストールした時に作られているargo-evemts-role
をバインドします。
- rbac.yaml
apiVersion: v1 kind: ServiceAccount metadata: name: argo-events-sa namespace: argo-sample --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: argo-sample-binding roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: argo-events-role subjects: - kind: ServiceAccount name: argo-events-sa namespace: argo-sample
Sensor自体はargo-sample
Namespaceにデプロイしますが、Sensorによって動くWorkflowはdefault
Namespaceで動かします。
あと上で作ったService Accountを指定しています。
- calendar-sensor.yaml
apiVersion: argoproj.io/v1alpha1 kind: Sensor metadata: name: calendar-sensor namespace: argo-sample # 作ったNamespace labels: sensors.argoproj.io/sensor-controller-instanceid: argo-events spec: template: spec: containers: - name: "sensor" image: "argoproj/sensor" imagePullPolicy: Always serviceAccountName: argo-events-sa #作ったService Account dependencies: - name: "calendar-gateway:interval" eventProtocol: type: "HTTP" http: port: "9300" triggers: - template: name: calendar-workflow-trigger group: argoproj.io version: v1alpha1 kind: Workflow source: inline: | apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: calendar-workflow- namespace: default # defaultを指定する spec: entrypoint: whalesay arguments: parameters: - name: message # this is the value that should be overridden value: hello world templates: - name: whalesay inputs: parameters: - name: message container: image: docker/whalesay:latest command: [cowsay] args: ["{{inputs.parameters.message}}"] resourceParameters: - src: event: "calendar-gateway:interval" dest: spec.arguments.parameters.0.value
Gatewayの設定です。今回は定期実行用の設定を定義しました。
以下の設定だと30sに1回発火されます。
こちらもargo-sample
Namespaceにデプロイします。
apiVersion: v1 kind: ConfigMap metadata: name: calendar-gateway-configmap namespace: argo-sample # 作ったNamespace data: interval: |- interval: 10s schedule: |- schedule: "30 * * * *"
Gatewayもargo-sample
Namespaceにデプロイします。
apiVersion: argoproj.io/v1alpha1 kind: Gateway metadata: name: calendar-gateway namespace: argo-sample # 作ったNamespace labels: gateways.argoproj.io/gateway-controller-instanceid: argo-events gateway-name: "calendar-gateway" spec: processorPort: "9330" eventProtocol: type: "HTTP" http: port: "9300" template: metadata: name: "calendar-gateway" labels: gateway-name: "calendar-gateway" spec: containers: - name: "gateway-client" image: "argoproj/gateway-client" imagePullPolicy: "Always" command: ["/bin/gateway-client"] - name: "calendar-events" image: "argoproj/calendar-gateway" imagePullPolicy: "Always" command: ["/bin/calendar-gateway"] serviceAccountName: "argo-events-sa" #作ったService Account configMap: "calendar-gateway-configmap" type: "calendar" eventVersion: "1.0" watchers: sensors: - name: "calendar-sensor"
デプロイ
上で定義したGatewayとSensorをデプロイしてみます。
$ ls calendar-gateway-configmap.yaml calendar-gateway.yaml calendar-sensor.yaml rbac.yaml $ kubectl create ns argo-sample $ kubectl apply -f . $ kubectl get gateway -n argo-sample NAME AGE calendar-gateway 16s $ kubectl get sensor -n argo-sample NAME AGE calendar-sensor 40s $ argo list NAME STATUS AGE DURATION calendar-workflow-g5bwc Running 4s 4s calendar-workflow-777sk Succeeded 14s 7s calendar-workflow-4gg49 Succeeded 24s 7s
Argo Eventsとは違うNamespaceにあるGatewayやSensorでも実行されていることが確認できます。
ブラウザでみてみると実行されていると思います。
http://127.0.0.1:8001/api/v1/namespaces/default/services/http:argo-ui:/proxy/
おわりに
本当はWorkflowも違うNamespaceで実行したかったのですが、違うNamespaceで実行するとUIからログが見れなくなるというバグがあるのでやりませんでした。
修正のプルリクはMasterに取り込まれているので、次のバージョンが出たらみられるようになっていると思います。
fix: fix get logs api, get namespace from parameters instead of query by jackfengji · Pull Request #18 · argoproj/argo-ui · GitHub