あとがきのようなもの

インフラ関連,コンテナ,仮想化技術、過去に書いた記事の解説など

【Podman v3.3.x】podman machineの自動ポートフォワード機能を使う

Podman v3.3.0からpodman machine内のコンテナに自動的にポートフォワードが行われる機能が追加された。 この機能についてはv3.3.0のリリースノートの一番初めに記載されている。

v3.3.0のリリースノートより抜粋

Containers inside VMs created by podman machine will now automatically handle port forwarding - containers in podman machine VMs that publish ports via --publish or --publish-all will have these ports not just forwarded on the VM, but also on the host system.

(翻訳)podman machine で作成された VM 内のコンテナは、ポートフォワーディングを自動的に処理するようになりました。--publish または --publish-all でポートを公開した podman machine VM 内のコンテナは、これらのポートが VM 上だけでなく、ホストシステム上にも転送されます。

podman machineとgvproxyによる自動ポートフォワードの使い方について解説。

gvproxyについて

自動ポートフォワードの機能の追加によりpodman machineを使うためにはgvproxyが必要になった。 このことはv3.3.0リリースノートのChangesに記載がある

The new port forwarding offered by podman machine requires gvproxy in order to function.

gvproxyはGitHubリポジトリ上ではgvisor-tap-vsockという名前になっている。libslirp と VPNKitを置き換えるものでGoで書かれており、gVisorのネットワークスタックをベースにしている。

gvproxy自体の使い方や詳細はGitHubリポジトリを参照。

github.com

rootモード on Linuxで実行する場合

rootモード on Linuxの実行環境

$ cat /proc/version
Linux version 5.13.12-200.fc34.x86_64 (mockbuild@bkernel01.iad2.fedoraproject.org) (gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1), GNU ld version 2.35.2-4.fc34) #1 SMP Wed Aug 18 13:27:18 UTC 2021
$ podman -r version
Client:
Version:      3.3.1
API Version:  3.3.1
Go Version:   go1.16.6
Built:        Tue Aug 31 05:46:36 2021
OS/Arch:      linux/amd64

Server:
Version:      3.3.0
API Version:  3.3.0
Go Version:   go1.16.6
Built:        Sat Aug 21 04:36:14 2021
OS/Arch:      linux/amd64

[実行手順]

  • podman machineの初期化と起動
  • nginxイメージのpull
  • TCP:8888を公開ポートとしてnginxコンテナを起動
  • 公開ポートの確認とcurlによる接続
# podman machine init; podman machine start
# podman -r pull docker.io/library/nginx
# podman -r run --rm -d --name nginx -p 8888:80 nginx
# podman -r ps
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS                 NAMES
b75a5a32c09a  docker.io/library/nginx:latest  nginx -g daemon o...  30 seconds ago  Up 30 seconds ago  0.0.0.0:8888->80/tcp  nginx
# ss -ltnup | grep 8888
tcp   LISTEN 0      4096               *:8888             *:*    users:(("gvproxy",pid=8857,fd=31))
# curl http://localhost:8888
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>

gvproxyを使って自動的にポートフォワーディングが行われ、ホスト上からpodman machine VM上のコンテナへ接続ができる

ルートレスモード on LinuxまたはmacOSで実行する場合

ルートレスモード on LinuxまたはmacOSで実行する場合は注意が必要。rootモードと同じ手順では自動的にポートフォワーディングが行われない。 この問題についてはGitHubにIssueを上げている。

github.com

Issueを上げてすぐにコメントが付いて、その内容のワークアラウンドを適用することでルートレスモードおよびmacOSで自動ポートフォワードが実行が可能となった。

ワークアラウンド

コンテナ実行時に--network bridgeを付与する

ルートレスモード on Linuxの場合

実行環境はrootモード on Linuxと同じ

[実行手順]

  • podman machineの初期化と起動
  • nginxイメージのpull
  • TCP:8888を公開ポートとしてnginxコンテナを起動
  • 公開ポートの確認とcurlによる接続
$ podman machine init; podman machine start
$ podman -r pull docker.io/library/nginx
$ podman -r run --rm -d --name nginx -p 8888:80 --network bridge nginx
$ ss -ltnup |grep 8888
tcp   LISTEN 0      4096               *:8888             *:*    users:(("gvproxy",pid=9725,fd=17))
$ curl http://localhost:8888
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>

macOSの場合

実行環境

$ podman version
Client:
Version:      3.3.1
API Version:  3.3.1
Go Version:   go1.17
Built:        Tue Aug 31 04:15:26 2021
OS/Arch:      darwin/amd64

Server:
Version:      3.3.0
API Version:  3.3.0
Go Version:   go1.16.6
Built:        Sat Aug 21 04:36:14 2021
OS/Arch:      linux/amd64

[実行手順]

  • podman machineの初期化と起動
  • nginxイメージのpull
  • TCP:8888を公開ポートとしてnginxコンテナを起動
  • 公開ポートの確認とcurlによる接続
$ podman machine init; podman machine start
$ podman pull docker.io/library/nginx
$ podman run --rm -d --name nginx -p 8888:80 --network bridge nginx
$ ss -ltnup |grep 8888
tcp   LISTEN 0      4096               *:8888             *:*    users:(("gvproxy",pid=9725,fd=17))
$curl http://localhost:8888
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>

別のワークアラウンド

GitHubのIssueでは議論が進んでおり、別のワークアラウンドとしてcontainers.confに設定を書き込む方法が紹介されている。

github.com

Just confirming that adding rootless_networking = "cni" under the [containers] section of ~/.config/containers/containers.conf does also fix this on MacOS :)

containers.conf[containers]セクションにrootless_networking = "cni"を追記する。

ルートレスモード on LinuxmacOS共通の手順

$ vi ~/.config/containers/containers.conf

[containers]
rootless_networking = "cni"

この設定を行うことでコンテナ実行時に--network bridgeを付与しなくても自動的にポートフォワードが行われるようになる。

ルートレスモード on Linuxの場合

$ podman -r run --rm -d --name nginx -p 8888:80 nginx
$ ss -ltnup |grep 8888
tcp   LISTEN 0      4096               *:8888             *:*    users:(("gvproxy",pid=9725,fd=14))
$ curl http://localhost:8888
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>

macOSの場合

$ podman run --rm -d --name nginx -p 8888:80 nginx
$ netstat -an|grep 8888
tcp46      0      0  *.8888                 *.*                    LISTEN
$ curl http://localhost:8888
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>

【RHEL】virt-who設定前に割り当てられる一時的なサブスクリプションの有効期間は7日間

Red Hat Enterprise Linux(以下、RHEL)のVirtual Data Centerサブスクリプション(以下、VDC)を購入後、virt-whoの設定が完了する前にはRHEL仮想マシンには一時的なサブスクリプションが付与される。

どういうことかというと、

というchicken-and-eggな状態になってしまう。

vSphereやNutanix AHV上などで最初に作ったRHEL仮想マシンをvirt-whoに仕立てようとしてもこの状態にハマってしまう。 これを解消するためにはvirt-whoを設定予定のRHEL仮想マシンRHEL VDCサブスクリプションをアタッチすることで、一時的なサブスクリプションとして使用が可能になる。本来ホスト側に適用するものを無理やり仮想マシンに割り当てるわけで、永続的ではなく一時的なサブスクリプションとなる。 この一時的な期限が7日間となっている。

下記は2021年8月27日にアタッチした場合。

仮想マシンにアタッチされた一時的なサブスクリプションの状態
仮想マシンにアタッチされた一時的なサブスクリプションの状態

以前は一時的なサブスクリプションの有効期間は24時間だった

過去のドキュメント、例えばRed Hat Satellite(以下、Satellite) 6.5には一時的なサブスクリプションは24時間有効となっている。

Satellite 6.6では7日間になっている。

時期的にはSatellite 6.6 がリリースされた頃から変更された?(リリース:2019年10月22日)

期間が短くなったわけではないし不都合は無いが、24時間経ったらどのような動作になるか確認したかったのでその検証はまた別環境で実施。

powerclicoreのアップデートとttyエコーのバグ

VMwareのPowerCLIを実行できるコンテナイメージがアップデートされていた(約二週間前には更新されていた模様)。

vmware/powerclicore - Docker Image | Docker Hub

  • 相変わらずlatest12.3.1のイメージが別物(DIGESTが異なる)になっていたりする

大きな変更点としてはPowerShellのインストール方法が変わってイメージの容量が3倍くらいに増えたこと。

更新前(TAG:12.3)
更新前(TAG:12.3)
更新後(TAG:12.3.1)
更新後(TAG:12.3.1)

せっかく容量削減するPR送ってマージされたのに無かったことにされてて残念。

github.com

更新の経緯

更新に関するPRはこちら。

github.com

PowerShellのバージョンが更新されたこと。もう一つが環境変数TERMの値が変更され、TERM=linuxからTERM=linux-basicになったこと。 変更のきっかけのIssueはこちら。

github.com

PowerShell Hashtablesが表示できないということで、Microsoftのイメージでは動作しPhotonがNGと。この修正のため環境変数TERMが変更された。

github.com

変更した結果、ttyで入力がエコーするバグが発生。

tty入力エコーのバグ

コンテナを実行してttyでキーを入力すると同じ文字が繰り返し入力されるバグ。基本的に操作不能なので環境変数TERMを変更するしかない。

個人的に作っていたPowerCLIのコンテナイメージでも先日まで似たようなバグが発生していた(上下左右カーソルキーが効かず、OA/OB/OC/ODが代わりに入力される)。こちらでは使っていたv7.2.0-preview.8で発生していたので、v7.1.4に変更して改善された。

github.com

まさかVMware公式イメージが同じようなバグを抱えたバージョンをリリースするとは思わなかった。

python36 moduleを無効にするとpipがインストールできない

ubi8-minimalを使ったコンテナイメージの容量削減の試行錯誤で確認。RHEL 8.xでも同様と想定される。

  • dnfでpython39python3-pipをインストールするとpython36とpython39 moduleが有効になっている
  • dnf install前にpython36 moduleを無効にするとpipがインストールできない

再現

(下記作業はubi8-minimalコンテナ内)

通常通りpython39python3-pipをインストール

[root@8f3c12facb9f /]# microdnf install --disableplugin=subscription-manager --nodocs -y python39 python3-pip

出力結果を開く

Downloading metadata...
Downloading metadata...
Downloading metadata...
Package                                                                                                                                        Repository                                               Size
Installing:
 gdbm-1:1.18-1.el8.x86_64                                                                                                                      ubi-8-baseos                                         132.9 kB
 gdbm-libs-1:1.18-1.el8.x86_64                                                                                                                 ubi-8-baseos                                          62.0 kB
 libnsl2-1.2.0-2.20180605git4a062cf.el8.x86_64                                                                                                 ubi-8-baseos                                          59.1 kB
 libtirpc-1.1.4-4.el8.x86_64                                                                                                                   ubi-8-baseos                                         115.5 kB
 platform-python-3.6.8-37.el8.x86_64                                                                                                           ubi-8-baseos                                          86.1 kB
 platform-python-pip-9.0.3-19.el8.noarch                                                                                                       ubi-8-baseos                                           1.8 MB
 platform-python-setuptools-39.2.0-6.el8.noarch                                                                                                ubi-8-baseos                                         647.5 kB
 python3-libs-3.6.8-37.el8.x86_64                                                                                                              ubi-8-baseos                                           8.2 MB
 python3-pip-9.0.3-19.el8.noarch                                                                                                               ubi-8-appstream                                       20.2 kB
 python3-pip-wheel-9.0.3-19.el8.noarch                                                                                                         ubi-8-baseos                                           1.1 MB
 python3-setuptools-39.2.0-6.el8.noarch                                                                                                        ubi-8-baseos                                         166.5 kB
 python3-setuptools-wheel-39.2.0-6.el8.noarch                                                                                                  ubi-8-baseos                                         295.8 kB
 python36-3.6.8-2.module+el8.1.0+3334+5cb623d7.x86_64                                                                                          ubi-8-appstream                                       19.6 kB
 python39-3.9.2-1.module+el8.4.0+10237+bdc77aac.x86_64                                                                                         ubi-8-appstream                                       32.8 kB
 python39-libs-3.9.2-1.module+el8.4.0+10237+bdc77aac.x86_64                                                                                    ubi-8-appstream                                        8.5 MB
 python39-pip-20.2.4-3.module+el8.4.0+9822+20bf1249.noarch                                                                                     ubi-8-appstream                                        2.1 MB
 python39-pip-wheel-20.2.4-3.module+el8.4.0+9822+20bf1249.noarch                                                                               ubi-8-appstream                                        1.3 MB
 python39-setuptools-50.3.2-3.module+el8.4.0+9822+20bf1249.noarch                                                                              ubi-8-appstream                                      891.6 kB
 python39-setuptools-wheel-50.3.2-3.module+el8.4.0+9822+20bf1249.noarch                                                                        ubi-8-appstream                                      508.5 kB
Transaction Summary:
 Installing:       19 packages
 Reinstalling:      0 packages
 Upgrading:         0 packages
 Obsoleting:        0 packages
 Removing:          0 packages
 Downgrading:       0 packages
Enabling module streams:
    python36:3.6
    python39:3.9


Downloading packages...
Running transaction test...
Installing: libtirpc;1.1.4-4.el8;x86_64;ubi-8-baseos
Installing: gdbm-libs;1:1.18-1.el8;x86_64;ubi-8-baseos
Installing: libnsl2;1.2.0-2.20180605git4a062cf.el8;x86_64;ubi-8-baseos
Installing: python3-pip-wheel;9.0.3-19.el8;noarch;ubi-8-baseos
Installing: python3-setuptools-wheel;39.2.0-6.el8;noarch;ubi-8-baseos
Installing: gdbm;1:1.18-1.el8;x86_64;ubi-8-baseos
Installing: platform-python-pip;9.0.3-19.el8;noarch;ubi-8-baseos
Installing: python3-libs;3.6.8-37.el8;x86_64;ubi-8-baseos
Installing: platform-python;3.6.8-37.el8;x86_64;ubi-8-baseos
Installing: platform-python-setuptools;39.2.0-6.el8;noarch;ubi-8-baseos
Installing: python3-setuptools;39.2.0-6.el8;noarch;ubi-8-baseos
Installing: python3-pip;9.0.3-19.el8;noarch;ubi-8-appstream
Installing: python36;3.6.8-2.module+el8.1.0+3334+5cb623d7;x86_64;ubi-8-appstream
Installing: python39-pip-wheel;20.2.4-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Installing: python39-setuptools-wheel;50.3.2-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Installing: python39-libs;3.9.2-1.module+el8.4.0+10237+bdc77aac;x86_64;ubi-8-appstream
Installing: python39;3.9.2-1.module+el8.4.0+10237+bdc77aac;x86_64;ubi-8-appstream
Installing: python39-setuptools;50.3.2-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Installing: python39-pip;20.2.4-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Complete.

  • python36とpython39 moduleが有効化されている
Enabling module streams:
    python36:3.6
    python39:3.9

python36 moduleを無効化してpython39python3-pipをインストール

[root@4fdfe700d1a3 /]# microdnf module disable python36

(microdnf:6): librhsm-WARNING **: 17:33:05.542: Found 0 entitlement certificates

(microdnf:6): librhsm-WARNING **: 17:33:05.544: Found 0 entitlement certificates
Downloading metadata...
Downloading metadata...
Downloading metadata...
Disabling modules:
    python36


Running transaction test...
[root@4fdfe700d1a3 /]# microdnf install --disableplugin=subscription-manager --nodocs -y python39 python3-pip
error: Could not depsolve transaction; 1 problem detected:
 Problem: package python3-pip-9.0.3-19.el8.noarch requires /usr/bin/python3.6, but none of the providers can be installed
  - package python3-pip-9.0.3-19.el8.noarch requires python36, but none of the providers can be installed
  - conflicting requests
  - package python36-3.6.8-2.module+el8.1.0+3334+5cb623d7.x86_64 is filtered out by modular filtering
  • エラーになってインストールができない

python36 moduleを有効化して再度python39python3-pipをインストール

[root@4fdfe700d1a3 /]# microdnf module enable python36

出力結果を開く

(microdnf:56): librhsm-WARNING **: 17:33:59.636: Found 0 entitlement certificates

(microdnf:56): librhsm-WARNING **: 17:33:59.637: Found 0 entitlement certificates
Enabling module streams:
    python36:3.6


Running transaction test...
[root@4fdfe700d1a3 /]# microdnf install --disableplugin=subscription-manager --nodocs -y python39 python3-pip
Package                                                                                                                                        Repository                                               Size
Installing:
 gdbm-1:1.18-1.el8.x86_64                                                                                                                      ubi-8-baseos                                         132.9 kB
 gdbm-libs-1:1.18-1.el8.x86_64                                                                                                                 ubi-8-baseos                                          62.0 kB
 libnsl2-1.2.0-2.20180605git4a062cf.el8.x86_64                                                                                                 ubi-8-baseos                                          59.1 kB
 libtirpc-1.1.4-4.el8.x86_64                                                                                                                   ubi-8-baseos                                         115.5 kB
 platform-python-3.6.8-37.el8.x86_64                                                                                                           ubi-8-baseos                                          86.1 kB
 platform-python-pip-9.0.3-19.el8.noarch                                                                                                       ubi-8-baseos                                           1.8 MB
 platform-python-setuptools-39.2.0-6.el8.noarch                                                                                                ubi-8-baseos                                         647.5 kB
 python3-libs-3.6.8-37.el8.x86_64                                                                                                              ubi-8-baseos                                           8.2 MB
 python3-pip-9.0.3-19.el8.noarch                                                                                                               ubi-8-appstream                                       20.2 kB
 python3-pip-wheel-9.0.3-19.el8.noarch                                                                                                         ubi-8-baseos                                           1.1 MB
 python3-setuptools-39.2.0-6.el8.noarch                                                                                                        ubi-8-baseos                                         166.5 kB
 python3-setuptools-wheel-39.2.0-6.el8.noarch                                                                                                  ubi-8-baseos                                         295.8 kB
 python36-3.6.8-2.module+el8.1.0+3334+5cb623d7.x86_64                                                                                          ubi-8-appstream                                       19.6 kB
 python39-3.9.2-1.module+el8.4.0+10237+bdc77aac.x86_64                                                                                         ubi-8-appstream                                       32.8 kB
 python39-libs-3.9.2-1.module+el8.4.0+10237+bdc77aac.x86_64                                                                                    ubi-8-appstream                                        8.5 MB
 python39-pip-20.2.4-3.module+el8.4.0+9822+20bf1249.noarch                                                                                     ubi-8-appstream                                        2.1 MB
 python39-pip-wheel-20.2.4-3.module+el8.4.0+9822+20bf1249.noarch                                                                               ubi-8-appstream                                        1.3 MB
 python39-setuptools-50.3.2-3.module+el8.4.0+9822+20bf1249.noarch                                                                              ubi-8-appstream                                      891.6 kB
 python39-setuptools-wheel-50.3.2-3.module+el8.4.0+9822+20bf1249.noarch                                                                        ubi-8-appstream                                      508.5 kB
Transaction Summary:
 Installing:       19 packages
 Reinstalling:      0 packages
 Upgrading:         0 packages
 Obsoleting:        0 packages
 Removing:          0 packages
 Downgrading:       0 packages
Enabling module streams:
    python39:3.9


Downloading packages...
Running transaction test...
Installing: libtirpc;1.1.4-4.el8;x86_64;ubi-8-baseos
Installing: gdbm-libs;1:1.18-1.el8;x86_64;ubi-8-baseos
Installing: libnsl2;1.2.0-2.20180605git4a062cf.el8;x86_64;ubi-8-baseos
Installing: python3-pip-wheel;9.0.3-19.el8;noarch;ubi-8-baseos
Installing: python3-setuptools-wheel;39.2.0-6.el8;noarch;ubi-8-baseos
Installing: gdbm;1:1.18-1.el8;x86_64;ubi-8-baseos
Installing: platform-python-pip;9.0.3-19.el8;noarch;ubi-8-baseos
Installing: python3-libs;3.6.8-37.el8;x86_64;ubi-8-baseos
Installing: platform-python;3.6.8-37.el8;x86_64;ubi-8-baseos
Installing: platform-python-setuptools;39.2.0-6.el8;noarch;ubi-8-baseos
Installing: python3-setuptools;39.2.0-6.el8;noarch;ubi-8-baseos
Installing: python3-pip;9.0.3-19.el8;noarch;ubi-8-appstream
Installing: python36;3.6.8-2.module+el8.1.0+3334+5cb623d7;x86_64;ubi-8-appstream
Installing: python39-pip-wheel;20.2.4-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Installing: python39-setuptools-wheel;50.3.2-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Installing: python39-libs;3.9.2-1.module+el8.4.0+10237+bdc77aac;x86_64;ubi-8-appstream
Installing: python39;3.9.2-1.module+el8.4.0+10237+bdc77aac;x86_64;ubi-8-appstream
Installing: python39-setuptools;50.3.2-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Installing: python39-pip;20.2.4-3.module+el8.4.0+9822+20bf1249;noarch;ubi-8-appstream
Complete.

  • python39 moduleが追加で有効化され、無事インストールが完了

Podman Community Cabal Meeting(2021/8/19)のログ

2021/8/19にPodman Community Cabal Meetingが開催された

Podman Community Cabal Meetingとは

Podman Community Cabal

毎月第三木曜日 10:00 ESTに開催。デザインに関する質問、問題、その他関連するトピックをPodmanプロジェクトのメンテナと話し合うために使用される。1時間のうち最後の20分はオープンフォーラムに使用。

https://podman.io/community/meeting/

2021/8/19開催のミーティングログ

hackmd.io

  • 録画はまだ未公開

ミーティングログから気になった点をピックアップ

  • Podman 4.0-devがアップストリームに登場
  • v4.0ではBuildahとPodmanのビルドにBuildkitが採用される
  • Podman on Windowsについて
    • WSL向けのソリューションを検討中
    • DockerにはWindows向けGUIがあるが同様のものをアウトオブボックスで提供することはないだろう
    • Microsoft StoraからFedora34の購入に10ドルかかる
    • Podmanを簡単にインストールできるようにしたい。問題点は時間をかけてアップデートし続けること。ベストケースはFedoraチームがFedoraをPodmanにプレインストールしてMicrosoft Storaに提供すること。
  • Podman v3.3は8/23、3.4は秋の後半リリース予定
  • Podman v4.0はFedora 35を逃すことができない。2022年4月にはFedora 36がリリースされる予定。Fedora 35を逃した場合のターゲットになると思われるがそうならないことを願っている。

次回開催

2021年9月16日木曜日午前10時EDT(UTC-4)