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.

Liberty InstantOn を Kubernetes で試してみた

Posted at

前回の記事で、Open Liberty の InstantOn を Ubuntu 環境で試してみました。
今回は、前回作成した InstantOn 用のイメージを利用して、Kubernetes 環境で InstantOn を試してみます。

利用した環境

利用した環境は、以下の通りです。
Podman でのイメージのビルドは、Ubuntu 22.04 で行いましたが、Kubernetes 用の Ubuntu は 20.04 のままです。ただし、無効化していた IP V6 を有効化しました。

  • Ubuntu 20.04 (IP v6 有効化)
  • Kubernetes v1.26.0
  • containerd 1.6.21

Open Liberty オペレーターのインストール

まずは、Open Liberty のオペレーターをインストールします。
下記 URL の手順を参考にしましたが、特に問題なく、インストールできました。
Open Liberty オペレーターは、ネームスペース liberty にインストールし、同じネームスペース内のカスタム・リソースをウォッチするようにしました。

Open Liberty オペレーターのインストール時のログ
root# kubectl apply --server-side -f https://raw.githubusercontent.com/OpenLiberty/open-liberty-operator/main/deploy/releases/1.2.1/kubectl/openliberty-app-crd.yaml
customresourcedefinition.apiextensions.k8s.io/openlibertyapplications.apps.openliberty.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/openlibertydumps.apps.openliberty.io serverside-applied
customresourcedefinition.apiextensions.k8s.io/openlibertytraces.apps.openliberty.io serverside-applied
root# OPERATOR_NAMESPACE=liberty
root# WATCH_NAMESPACE=liberty
root# curl -L https://raw.githubusercontent.com/OpenLiberty/open-liberty-operator/main/deploy/releases/1.2.1/kubectl/openliberty-app-operator.yaml \
      | sed -e "s/OPEN_LIBERTY_WATCH_NAMESPACE/${WATCH_NAMESPACE}/" \
      | kubectl apply -n ${OPERATOR_NAMESPACE} -f -
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  6816  100  6816    0     0  19410      0 --:--:-- --:--:-- --:--:-- 19363
serviceaccount/olo-controller-manager created
role.rbac.authorization.k8s.io/olo-leader-election-role created
role.rbac.authorization.k8s.io/olo-manager-role created
rolebinding.rbac.authorization.k8s.io/olo-leader-election-rolebinding created
rolebinding.rbac.authorization.k8s.io/olo-manager-rolebinding created
deployment.apps/olo-controller-manager created
root# kubectl get pod
NAME                                      READY   STATUS    RESTARTS      AGE
olo-controller-manager-59f76fd48f-nr59z   1/1     Running   0             62s
root# 

カスタム・リソースの作成

Open Liberty オペレーター用のカスタム・リソース instant-on.yaml を作成します。
(下に instant-on.yaml の全体を載せておきます。)

instant-on.yaml 全量
apiVersion: apps.openliberty.io/v1
kind: OpenLibertyApplication
metadata:
  name: instant-on
  namespace: liberty
spec:
  applicationImage: registry.local/liberty-instant-on:v1.0.0
  pullPolicy: IfNotPresent
  replicas: 1
  env:
    - name: WLP_LOGGING_CONSOLE_FORMAT
      value: SIMPLE
  manageTLS: false
  service:
    port: 9080
  expose: true
  securityContext:
    runAsNonRoot: true
    privileged: false
    allowPrivilegeEscalation: true
    capabilities:
      add:
      - CHECKPOINT_RESTORE
      - SYS_PTRACE
      - SETPCAP
      drop:
      - ALL
  route:
    host: liberty.local
    pathType: Prefix
    path: /
    annotations:
      kubernetes.io/ingress.class: nginx
      nginx.ingress.kubernetes.io/affinity: cookie
      nginx.ingress.kubernetes.io/rewrite-target: /
      nginx.ingress.kubernetes.io/session-cookie-hash: sha1
      nginx.ingress.kubernetes.io/session-cookie-name: route
  monitoring:
    labels:
      release: kube-prometheus-stack
    endpoints:
      - port: 9080-tcp
        path: /metrics
        interval: 30s

instant-on.yaml では、前回 Podman で作成した、InstantOn 用のイメージを指定します。
InstantOn の恩恵を受け、Pod を短時間で起動することを考えると、pullPolicy には IfNotPresent を指定することになると思います。そのため、常に、最新のイメージを使用するには、イメージのビルド毎に異なるタグを使用することが必要になります。

spec:
  ...
  applicationImage: registry.local/liberty-instant-on:v1.0.0
  pullPolicy: IfNotPresent

さらに、InstantOn を有効にするために、以下の定義を追加します。
追加したケーパビリティは、前回 Ubuntu&Podman 環境で InstantOn を試した時と同様に、以下の3つです。

  • CHECKPOINT_RESTORE
  • SYS_PTRACE
  • SETPCAP
spec:
  ....
  securityContext:
    runAsNonRoot: true
    privileged: false
    allowPrivilegeEscalation: true
    capabilities:
      add:
      - CHECKPOINT_RESTORE
      - SYS_PTRACE
      - SETPCAP
      drop:
      - ALL

Pod のデプロイ

作成したカスタム・リソースを適用して、Open Liberty の Pod を起動します。

root# kubectl apply -f instant-on.yaml
openlibertyapplication.apps.openliberty.io/instant-on created
root# 

起動された Pod のコンソール出力を確認すると、InstantOn で起動されていることが確認できます。今回の起動時間は、started in 0.113 seconds となっていました。

root# kubectl get pod
NAME                                      READY   STATUS    RESTARTS       AGE
instant-on-798f4dfb9c-24hjn               1/1     Running   0              4s
olo-controller-manager-59f76fd48f-nr59z   1/1     Running   0              76m
root# kubectl logs instant-on-798f4dfb9c-24hjn

[7/13/23, 5:04:13:584 UTC] 00000036 com.ibm.ws.kernel.launch.internal.FrameworkManager           A Launching defaultServer (Open Liberty 23.0.0.7-beta/wlp-1.0.78.cl230620230612-1100) on Eclipse OpenJ9 VM, version 17.0.7+7 (en_US)
[7/13/23, 5:04:13:592 UTC] 00000036 com.ibm.ws.app.manager.AppMessageHelper                      A CWWKZ0001I: Application SimpleWebTest started in 0.087 seconds.
[7/13/23, 5:04:13:602 UTC] 00000036 com.ibm.ws.http.internal.VirtualHostImpl                     A CWWKT0016I: Web application available (default_host): http://instant-on-798f4dfb9c-24hjn:9080/SimpleWebTest/
[7/13/23, 5:04:13:612 UTC] 00000036 io.openliberty.checkpoint.internal.CheckpointImpl            A CWWKC0452I: The Liberty server process resumed operation from a checkpoint in 0.107 seconds.
[7/13/23, 5:04:13:612 UTC] 0000003c com.ibm.ws.security.token.ltpa.internal.LTPAKeyCreateTask    I CWWKS4105I: LTPA configuration is ready after 0.010 seconds.
[7/13/23, 5:04:13:613 UTC] 00000036 com.ibm.ws.tcpchannel.internal.TCPPort                       I CWWKO0219I: TCP Channel defaultHttpEndpoint has been started and is now listening for requests on host *  (IPv6) port 9080.
[7/13/23, 5:04:13:617 UTC] 00000036 com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0012I: The server installed the following features: [appSecurity-2.0, appSecurity-3.0, beanValidation-2.0, cdi-2.0, distributedMap-1.0, ejbLite-3.2, el-3.0, jaspic-1.1, jaxrs-2.1, jaxrsClient-2.1, jdbc-4.2, jndi-1.0, jpa-2.2, jpaContainer-2.2, jsf-2.3, jsonb-1.0, jsonp-1.1, jsp-2.3, managedBeans-1.0, servlet-4.0, ssl-1.0, transportSecurity-1.0, webProfile-8.0, websocket-1.1].
[7/13/23, 5:04:13:618 UTC] 00000036 com.ibm.ws.kernel.feature.internal.FeatureManager            I CWWKF0008I: Feature update completed in 0.113 seconds.
[7/13/23, 5:04:13:618 UTC] 00000036 com.ibm.ws.kernel.feature.internal.FeatureManager            A CWWKF0011I: The defaultServer server is ready to run a smarter planet. The defaultServer server started in 0.113 seconds.
[7/13/23, 5:04:13:672 UTC] 00000032 com.ibm.ws.ssl.config.WSKeyStore                             I Successfully loaded default keystore: /opt/ol/wlp/output/defaultServer/resources/security/key.p12 of type: PKCS12
[7/13/23, 5:04:13:682 UTC] 00000036 com.ibm.ws.tcpchannel.internal.TCPPort                       I CWWKO0219I: TCP Channel defaultHttpEndpoint-ssl has been started and is now listening for requests on host *  (IPv6) port 9443.
root#

終わりに

思ったよりも順調に、Kubernetes 環境で Open Liberty の InstantOn を試すことができました。
InstantOn を Azure Kubernetes Service で利用する例が以下の URL に記載されています。この記事でも、以下の URL の内容を参考にしました。

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?