1
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?

IBM Cloud ROKS環境で Podmanを用いてICRからコンテナイメージを取得・実行する手順

Last updated at Posted at 2025-07-08

概要

  • IBM Cloud OpenShift 4.15(ROKS)クラスター上で ネットワーク疎通チェック を手早く行いたいとき、curl や nslookup を備えた BusyBox Pod があると便利です。
    しかし企業環境では外部レジストリーへの直接 pull が制限されている場合が多いため、あらかじめ Podman で BusyBox イメージを ICR(IBM Cloud Container Registry) にプッシュしておき、クラスター内から pull → 起動できるようにしておくと運用がスムーズになります。

この記事では 「ローカル → ICR → ROKS」 の流れで BusyBox イメージを準備し、oc run で即席テスト Pod をデプロイするまでの手順を解説します。

[本記事での実行したいことのイメージ]

┌──────────────────────────┐   podman push    ┌──────────────────────┐
  ローカル端末 (Podman)   │─────────────--──▶│  ICR プライベート     
   - busybox:latest                             レジストリー        
└──────────────────────────┘                  └──────────────────────┘
                                                          
         oc run + image pull                               pull
                                                          
┌──────────────────────────────────────────────────────────────────────┐
  IBM Cloud OpenShift 4.15 クラスター (ROKS)                          
    ┌───────────────┐                                                 
     busybox Pod       `curl <URL>`, `nslookup <host>` など実行     
    └───────────────┘                                                 
└──────────────────────────────────────────────────────────────────────┘

1. ICRへのアップロード準備

1-1. Podmanをインストール

$ brew install podman
(logは省略)

1-2. Podman 仮想マシンを作成

macOS 版は Linux VM 上で動くため、最初に 1 度だけ VM を初期化

% podman machine init
Looking up Podman Machine image at quay.io/podman/machine-os:5.3 to create VM
Getting image source signatures
Copying blob cc337dac08f3 done   |
Copying config 44136fa355 done   |
Writing manifest to image destination
cc337dac08f317e9141e55f324d3af74f5d72f39c797f8d1f396948854fa655d
Extracting compressed file: podman-machine-default-arm64.raw: done
Machine init complete
To start your machine run:

	podman machine start

%

1-3. 仮想マシンを起動

% podman machine start
Starting machine "podman-machine-default"

This machine is currently configured in rootless mode. If your containers
require root permissions (e.g. ports < 1024), or if you run into compatibility
issues with non-podman clients, you can switch using the following command:

	podman machine set --rootful

API forwarding listening on: /var/folders/8_/3smd50j55qx5l52g8075hxw80000gn/T/podman/podman-machine-default-api.sock

The system helper service is not installed; the default Docker API socket
address can't be used by podman. If you would like to install it, run the following commands:

        sudo /opt/homebrew/Cellar/podman/5.3.1/bin/podman-mac-helper install
        podman machine stop; podman machine start

You can still connect Docker API clients by setting DOCKER_HOST using the
following command in your terminal session:

        export DOCKER_HOST='unix:///var/folders/8_/3smd50j55qx5l52g8075hxw80000gn/T/podman/podman-machine-default-api.sock'

Machine "podman-machine-default" started successfully
%

1-4. podmanが操作端末にインストールされたことを確認

% podman version
Client:       Podman Engine
Version:      5.3.1
API Version:  5.3.1
Go Version:   go1.23.3
Git Commit:   4cbdfde5d862dcdbe450c0f1d76ad75360f67a3c
Built:        Thu Nov 21 22:40:20 2024
OS/Arch:      darwin/arm64

Server:       Podman Engine
Version:      5.3.2
API Version:  5.3.2
Go Version:   go1.23.4
Built:        Wed Jan 22 09:00:00 2025
OS/Arch:      linux/arm64
%
% podman machine list
NAME                     VM TYPE     CREATED        LAST UP            CPUS        MEMORY      DISK SIZE
podman-machine-default*  applehv     5 minutes ago  Currently running  4           2GiB        100GiB
%

2. IBMCloudへのログインおよびICRへのログイン

2-1. IBM CloudへCLIログイン

% ibmcloud login --sso

2-2. ResourceGroup、Regionの指定 (各自環境に合わせて変更する)

% ibmcloud target -g <ResourceGroupName> -r jp-tok

2-3. ICRにもログイン

% ibmcloud cr login

もし手順1のPodmanセットアップが行われていないと、以下podmanが導入されていない旨エラーが出るので注意。

% ibmcloud cr login
Logging 'podman' in to 'icr.io'...
FAILED
Failed to 'podman login' to 'icr.io' with error: Cannot connect to Podman. Please verify your connection to the Linux system using `podman system connection list`, or try `podman machine init` and `podman machine start` to manage a new Linux VM
Error: unable to connect to Podman socket: Get "http://d/v5.3.1/libpod/_ping": dial unix /var/folders/8_/3smd50j55qx5l52g8075hxw80000gn/T/storage-run-501/podman/podman.sock: connect: no such file or directory
.

2-4. 今回busyboxイメージを保管するためのネームスペース場所を新規作成

  • 以下では、test-nsという名前で作成を行っている(任意の名前をつける)
$ ibmcloud cr namespace-add test-ns

eranaoki@Naokis-MacBook-Pro Work % ibmcloud cr namespace-add test-ns
Adding namespace 'test-ns' in resource group 'acs-xxxx' for account XXXXXXXXX Account in registry icr.io...

Successfully added namespace 'test-ns'

OK
%
  • namespaceが作成されたことを確認
% ibmcloud cr namespace-list
Listing namespaces for account 'XXXXXX's Account' in registry 'icr.io'...

Namespace
test-ns

OK
%

3. ICRへbusyboxイメージをアップロード

3-1. 最新イメージを端末にPullする

% podman pull --platform linux/amd64 busybox:latest
Resolved "busybox" as an alias (/etc/containers/registries.conf.d/000-shortnames.conf)
Trying to pull docker.io/library/busybox:latest...
Getting image source signatures
Copying blob sha256:90b9666d4aed1893ff122f238948dfd5e8efdcf6c444fe92371ea0f01750bf8c
Copying config sha256:6d3e4188a38af91b0c1577b9e88c53368926b2fe0e1fb985d6e8a70040520c4d
Writing manifest to image destination
6d3e4188a38af91b0c1577b9e88c53368926b2fe0e1fb985d6e8a70040520c4d
%

上記、"--platform linux/amd64"オプションをいれることを忘れずに入れてください。
利用している端末(今回であればMAC M1CPU)で利用するイメージファイル(ARM版)をダウンロードしてきてしまうため、Openshift(RHEL8)上で稼働しません。

3-2. ICR 用の名前(namespace)にタグ付け

% podman tag busybox:latest icr.io/test-ns/busybox:latest
%

3-3. ICRにイメージをPushする

% podman push icr.io/test-ns/busybox:latest
Getting image source signatures
Copying blob sha256:65014c70e84b6817fac42bb201ec5c1ea460a8da246cac0e481f5c9a9491eac0
Copying config sha256:6d3e4188a38af91b0c1577b9e88c53368926b2fe0e1fb985d6e8a70040520c4d
Writing manifest to image destination
%

4. Clusterへログインし、ICRのイメージを利用してPodの起動を行う

4-1. OpenshiftCluster 4.15へのログイン

% ibmcloud ks cluster config -c <CLUSTERID> --admin

4-2. OpenshiftCluster上でbusyboxPodへアクセス

 % oc run dns-test \
  --rm -i --tty \
  --image icr.io/test-ns/busybox:latest \
  --restart=Never \
  -- /bin/sh
  
If you don't see a command prompt, try pressing enter.
/ #

これで上記OpenshiftPod上に一時的に作成したbusyboxにアクセスできることが出来ました。
Clusterからのnslookup等の簡単なNW通信テストができます。
(注: pingを行う場合はOpenshiftのPodのSCCセキュリティ制御でRoot権限がない旨エラーがでるので、特権付きPod起動にする必要があります。)

/ # ifconfig
eth0      Link encap:Ethernet  HWaddr 7A:B1:DA:40:F8:44
          inet addr:172.22.51.83  Bcast:0.0.0.0  Mask:255.255.255.255
          inet6 addr: fe80::78b1:daff:fe40:f844/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1480  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:446 (446.0 B)  TX bytes:586 (586.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

/ # nslookup www.google.co.jp
Server:		172.21.0.10
Address:	172.21.0.10:53

Non-authoritative answer:
Name:	www.google.co.jp
Address: 142.250.207.3

Non-authoritative answer:
Name:	www.google.co.jp
Address: 2404:6800:4004:820::2003

/ #

  • 以上、IBM Cloud ROKS 環境で Podman と ICR を活用して BusyBox Pod を起動し、ネットワーク疎通確認を行うまでの手順をご紹介しました。
    実運用やトラブルシューティングの現場で、ぜひお役立てください。
1
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
1
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?