FreeBSD 14
Sponsored Link

Podman : Pod を作成する2024/03/05

 
Kubernetes でおなじみの Pod も Podman で作成可能です。
[1] Pod を作成してコンテナーを追加します。
root@dlp:~ #
vi /usr/local/etc/containers/containers.conf
# 411行目 : 追記

infra_image = "k8s.gcr.io/pause:3.8"
# pause イメージを pull

root@dlp:~ #
podman pull --os=linux k8s.gcr.io/pause:3.8
# 空の pod を新規作成
# -p [バインドするポート] -n [pod の名前]

root@dlp:~ #
podman pod create -p 8081:80 -n test-pod

WARN[0000] image platform (linux/amd64) does not match the expected platform (freebsd/amd64)
198d74eb556be4e91a38594c7a32b5cd0397b999fb914e0fc283400101b86e58

# 確認

root@dlp:~ #
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
198d74eb556b  test-pod    Created     15 seconds ago  5c76fd75bbe1  1

# pod の詳細を表示

root@dlp:~ #
podman pod inspect test-pod

{
     "Id": "198d74eb556be4e91a38594c7a32b5cd0397b999fb914e0fc283400101b86e58",
     "Name": "test-pod",
     "Created": "2024-03-05T08:56:50.851623418+09:00",
     "CreateCommand": [
          "podman",
          "pod",
          "create",
          "-p",
          "8081:80",
          "-n",
          "test-pod"
     ],
     "ExitPolicy": "continue",
     "State": "Created",
     "Hostname": "",
     "CreateCgroup": true,
     "CreateInfra": true,
     "InfraContainerID": "5c76fd75bbe12f1dec8341661fae79a94b5d5feb0e5b598fb64bf4a8f0c5fc8f",
     "InfraConfig": {
          "PortBindings": {
               "80/tcp": [
                    {
                         "HostIp": "",
                         "HostPort": "8081"
                    }
               ]
          },
          "HostNetwork": false,
          "StaticIP": "",
          "StaticMAC": "",
          "NoManageResolvConf": false,
          "DNSServer": null,
          "DNSSearch": null,
          "DNSOption": null,
          "NoManageHosts": false,
          "HostAdd": null,
          "Networks": [
               "podman"
          ],
          "NetworkOptions": null,
          "pid_ns": "private",
          "userns": "host",
          "uts_ns": "private"
     },
     "SharedNamespaces": [
          "ipc",
          "net",
          "uts"
     ],
     "NumContainers": 1,
     "Containers": [
          {
               "Id": "5c76fd75bbe12f1dec8341661fae79a94b5d5feb0e5b598fb64bf4a8f0c5fc8f",
               "Name": "198d74eb556b-infra",
               "State": "created"
          }
     ],
     "security_opt": [
          "unmask=all"
     ],
     "LockNumber": 51
}

root@dlp:~ #
podman images

REPOSITORY                TAG         IMAGE ID      CREATED        SIZE
localhost/freebsd-nginx   latest      a0a053cc78a3  5 days ago     1.17 GB
localhost/freebsd-httpd   latest      add46dedb2b7  5 days ago     1.44 GB
localhost/freebsd-base    latest      2527bfa5eeb4  6 days ago     1.05 GB
quay.io/centos/centos     stream9     ce3ac91d4020  2 weeks ago    161 MB
docker.io/library/ubuntu  latest      3db8720ecbf5  2 weeks ago    80.4 MB
k8s.gcr.io/pause          3.8         4873874c08ef  20 months ago  718 kB

# コンテナーを起動して pod に追加する

root@dlp:~ #
podman run -dt --pod test-pod localhost/freebsd-nginx

434e30ffcdeb886702f744422f0b10667582c624b80bfca61c6ec98c05c795d8

root@dlp:~ #
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED             STATUS        PORTS                 NAMES
5c76fd75bbe1  k8s.gcr.io/pause:3.8                                  About a minute ago  Up 6 seconds  0.0.0.0:8081->80/tcp  198d74eb556b-infra
434e30ffcdeb  localhost/freebsd-nginx:latest  /usr/local/sbin/n...  6 seconds ago       Up 6 seconds  0.0.0.0:8081->80/tcp  jovial_taussig

# アクセス確認

root@dlp:~ #
ssh freebsd@node01.srv.world "curl -s http://`hostname`:8081"

(freebsd@node01.srv.world) Password for freebsd@node01.srv.world:
Dockerfile Test on Nginx
# pod を停止する

root@dlp:~ #
podman pod stop test-pod

198d74eb556be4e91a38594c7a32b5cd0397b999fb914e0fc283400101b86e58

# pod を削除する (コンテナーも含めて強制削除)

root@dlp:~ #
podman pod rm test-pod --force

198d74eb556be4e91a38594c7a32b5cd0397b999fb914e0fc283400101b86e58
[2] Pod の作成とコンテナーの追加を同時に実行することもできます。
root@dlp:~ #
podman images

REPOSITORY                 TAG         IMAGE ID      CREATED        SIZE
localhost/freebsd-nginx    latest      a0a053cc78a3  5 days ago     1.17 GB
localhost/freebsd-httpd    latest      add46dedb2b7  5 days ago     1.44 GB
localhost/freebsd-base     latest      2527bfa5eeb4  6 days ago     1.05 GB
quay.io/centos/centos      stream9     ce3ac91d4020  2 weeks ago    161 MB
docker.io/library/ubuntu   latest      3db8720ecbf5  2 weeks ago    80.4 MB
k8s.gcr.io/pause           3.8         4873874c08ef  20 months ago  718 kB

# [test-pod2] を新規作成して [localhost/freebsd-nginx] コンテナーを追加する

root@dlp:~ #
podman run -dt --pod new:test-pod2 -p 80:80 localhost/freebsd-nginx

WARN[0000] image platform (linux/amd64) does not match the expected platform (freebsd/amd64)
fa385d7050e61b7738356effb9e1bc7e8781f16b5e3a0fdd2179aa1cc24cae64

root@dlp:~ #
podman pod ls

POD ID        NAME        STATUS      CREATED         INFRA ID      # OF CONTAINERS
5b07261b6ca0  test-pod2   Running     12 seconds ago  246b87d7c807  2

root@dlp:~ #
podman ps

CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS         PORTS               NAMES
246b87d7c807  k8s.gcr.io/pause:3.8                                  21 seconds ago  Up 21 seconds  0.0.0.0:80->80/tcp  5b07261b6ca0-infra
fa385d7050e6  localhost/freebsd-nginx:latest  /usr/local/sbin/n...  21 seconds ago  Up 21 seconds  0.0.0.0:80->80/tcp  sharp_leavitt

root@dlp:~ #
ssh freebsd@node01.srv.world "curl -s http://`hostname`"

(freebsd@node01.srv.world) Password for freebsd@node01.srv.world:
Dockerfile Test on Nginx
関連コンテンツ