2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【IBM Application Gateway】OpenShift GitOps(Argo CD)を使ってアプリをデプロイする

Last updated at Posted at 2022-06-02

はじめに

OpenShift GitOpsを設定して、IBM Application Gatewayをデプロイする流れを試しました。

1.OpenShift GitOpsの導入

Red Hat OpenShift on IBM Cloudで、OpenShift GitOpsを試す (導入編)を参考に導入しました。
その後、Red Hat OpenShift on IBM Cloudで、OpenShift GitOpsを試す (アプリデプロイ編)を参考にしながらアプリをデプロイしてみました。

qiita (1).png

2. IBM Application Gatewayのマニフェストを用意する。

IBM Application Gateway Deployment Assetsにあるテンプレート(iag-build-template.yaml)や、Buildconfigなどの定義を使ってデプロイしてみましたが、ArgoCDではうまくデプロイできませんでした。

例)Buildconfigを利用した場合は、Podは起動したが、Syncのステータスが「Out Of Sync」になった。
qiita (9).png

Red Hat OpenShift on IBM Cloudで、OpenShift GitOpsを試す (アプリデプロイ編)を参考にして、IBM Application GatewayのDeployment/Service/Routeのマニフェストを用意しました。

iag-sso.yaml
apiVersion: v1
items:
- apiVersion: apps/v1
  kind: Deployment
  metadata:
      name: iag
      labels:
        app: iag
        name: iag
  spec:
      progressDeadlineSeconds: 600
      replicas: 2
      revisionHistoryLimit: 10
      selector:
        matchLabels:
          app: iag
      strategy:
        rollingUpdate:
          maxSurge: 1
          maxUnavailable: 1
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: iag
            name: iag
        spec:
          serviceAccountName: default
          affinity:
            podAntiAffinity:
              preferredDuringSchedulingIgnoredDuringExecution:
              - weight: 100
                podAffinityTerm:
                  labelSelector:
                    matchExpressions:
                    - key: app
                      operator: In
                      values:
                      - iag
                  topologyKey: kubernetes.io/hostname
          containers:
          - env:
            - name: LANG
              value: jp
            envFrom:
              - configMapRef:
                  name: iag
              - secretRef:
                  name: iag
            image: docker.io/ibmcom/ibm-application-gateway:21.04
            imagePullPolicy: IfNotPresent
            name: iag
            ports:
            - containerPort: 8443
              protocol: TCP
            resources: 
              requests:
                cpu: 100m
                memory: 256Mi
              limits:
                memory: 256Mi
            terminationMessagePath: /dev/termination-log
            terminationMessagePolicy: File
            livenessProbe:
              exec:
                command:
                - /sbin/health_check.sh
              initialDelaySeconds: 120
              periodSeconds: 10
            readinessProbe:
              exec:
                command:
                - /sbin/health_check.sh
              initialDelaySeconds: 5
              periodSeconds: 10
            volumeMounts:
            - mountPath: /var/iag/config
              name: iag-config
            - mountPath: /var/iag/config/secret_files
              name: iag-secret-files
            - mountPath: /var/iag/config/env_files
              name: iag-env-files
          dnsPolicy: ClusterFirst
          restartPolicy: Always
          schedulerName: default-scheduler
          terminationGracePeriodSeconds: 30
          volumes:
          - name: iag-config
            configMap:
              name: iag-config
          - name: iag-secret-files
            secret:
              secretName: iag
          - name: iag-env-files
            configMap:
              name: iag
- apiVersion: route.openshift.io/v1
  kind: Route
  metadata:
    labels:
      name: iag
      app: iag
    name: iag
  spec:
    port:
      targetPort: iag
    tls:
      insecureEdgeTerminationPolicy: Redirect
      termination: passthrough
    to:
      kind: Service
      name: iag
      weight: 100
    wildcardPolicy: None
- apiVersion: v1
  kind: Service
  metadata:
    name: iag
    labels:
      app: iag
      name: iag
  spec:
    ports:
    - name: iag
      port: 443
      protocol: TCP
      targetPort: 8443
    selector:
      name: iag
    sessionAffinity: ClientIP
    sessionAffinityConfig:
      clientIP:
        timeoutSeconds: 10800
    type: ClusterIP
  status:
    loadBalancer: {}
kind: List
metadata: {}

このマニフェストをgithubに配置しておきます。
qiita (10).png

3. OpenShift GitOpsを使って、アプリをデプロイする

最初に、プロジェクトを作成します。

PS C:\temp-openshift\iag> oc new-project iag-gitops

シェルを使ってSecretとConfigmapを登録しておきます。

PS C:\temp-openshift\iag>.\openshift\create-iag-assets.sh

また、IBM Application GatewayのPod内に配置する設定ファイルを、iag-config という名前のConfigmapに登録します。
以下の例では、C:\temp-openshift\iag\configs\hello-world\srcディレクトリにあるファイルをConfigmapとして登録しています。

PS C:\temp-openshift\iag> oc create configmap iag-config --from-file=C:\temp-openshift\iag\configs\hello-world\src\

ArgoCDのServiceAccoutにCluster-adminのcluster-roleを割り当てます。

PS C:\temp-openshift\iag> oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controller -n openshift-gitops
clusterrole.rbac.authorization.k8s.io/cluster-admin added: "system:serviceaccount:openshift-gitops:openshift-gitops-argocd-application-controller"

Openshiftのコンソール右上にあるタイルアイコンから、Cluster Argo CDをクリックします。
qiita (3).png

ユーザー名:admin、パスワード:「アプリデプロイ編のガイドにある手順」でSecretからコピーした値を使ってログインします。
qiita (4).png

ログイン後の画面が表示されます。
qiita (5).png

アプリデプロイ編のガイドに従ってリポジトリ設定をおこないます。
入力してConnectをクリックします。
qiita (6).png

Successfulになっていることを確認します。
qiita (7).png

New-appをクリックします。
qiita (8).png

ガイドに従って設定してCreateボタンをクリックします。
qiita (11).png
qiita (12).png
qiita (13).png

登録されたアプリをクリックします。
qiita (14).png

Syncedステータスになり、Podが起動していることを確認します。
qiita (15).png

RouteのURLを取得します。

PS C:\temp-openshift\iag> oc get route
NAME   HOST/PORT                                                                                                         PATH   SERVICES   PORT   TERMINATION            WILDCARD
iag    iag-iag-gitops.xxxxxxxxxx.cloud          iag        iag    passthrough/Redirect   None

ブラウザでアクセスします。Security Verifyで認証すると、IBM Application Gatewayの画面が表示されます。
qiita (16).png

4. Githubのソースを変更して、自動的に反映されることを確認する。

現在のPodのイメージが「docker.io/ibmcom/ibm-application-gateway:21.04」であることを確認します。
qiita (17).png

iag-sso.yamlファイルの値を21.04から21.06に変更します。

~~割愛~~
containers:
          - env:
            - name: LANG
              value: jp
            envFrom:
              - configMapRef:
                  name: iag
              - secretRef:
                  name: iag
            image: docker.io/ibmcom/ibm-application-gateway:21.06 ###21.04から21.06に変更
            imagePullPolicy: IfNotPresent
~~割愛~~

githubに変更を反映します。

PS C:\temp-openshift\iag> git commit -a -m "mod"
[master a6121d1] mod
 1 file changed, 0 insertions(+), 0 deletions(-)
PS C:\temp-openshift\iag> git push
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 408 bytes | 204.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To https://github.com/xxx/iag
   c60ee76..a6121d1  master -> master

Argo CDは3分おきにリポジトリの変更をみてるので、デプロイが始まるまで待ちます。
自動同期が始まり、Podなど更新が入ります。
qiita (18).png

自動同期が終わるまで待ちます。
qiita (19).png

Podのイメージが「docker.io/ibmcom/ibm-application-gateway:21.06」に変わったことを確認します。
qiita (20).png

最後に

今回は、OpenShift GitOps(Argo CD)を使って、IBM Application Gatewayのデプロイしてみました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?