Fedora 34
Sponsored Link

Podman : Create Pods
2021/05/14
 
Create Pods like Kubernetes.
[1] Create a Pod and add a Container to it.
# create a empty pod

# -p [bind port] -n [pod name]

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

71003c6f96171c46c9619eba56be3238c33186bc66b9d4fd8fea551cda113e35

# show pods

[root@dlp ~]#
podman pod ls

POD ID        NAME      STATUS   CREATED         INFRA ID      # OF CONTAINERS
71003c6f9617  test-pod  Created  10 seconds ago  c8fb08d89c38  1

# show details of pod

[root@dlp ~]#
podman pod inspect test-pod

{
     "Id": "71003c6f96171c46c9619eba56be3238c33186bc66b9d4fd8fea551cda113e35",
     "Name": "test-pod",
     "Created": "2021-05-13T03:56:08.299508215-04:00",
     "CreateCommand": [
          "podman",
          "pod",
          "create",
          "-p",
          "8081:80",
          "-n",
          "test-pod"
     ],
     "State": "Created",
     "Hostname": "test-pod",
     "CreateCgroup": true,
     "CgroupParent": "machine.slice",
     "CgroupPath": "machine.slice/machine-libpod_pod_71003c6f96171c46c9619eba56be3238c33186bc66b9d4fd8fea551cda113e35.slice",
     "CreateInfra": true,
     "InfraContainerID": "c8fb08d89c385ff722af56854930caba442a3f29ebde70aaf5aa495b3245ad29",
     "InfraConfig": {
          "PortBindings": {
               "80/tcp": [
     {
          "HostIp": "",
          "HostPort": "8081"
     }
]
          },
          "HostNetwork": false,
          "StaticIP": "",
          "StaticMAC": "",
          "NoManageResolvConf": false,
          "DNSServer": null,
          "DNSSearch": null,
          "DNSOption": null,
          "NoManageHosts": false,
          "HostAdd": null,
          "Networks": null,
          "NetworkOptions": null
     },
     "SharedNamespaces": [
          "net",
          "uts",
          "ipc"
     ],
     "NumContainers": 1,
     "Containers": [
          {
               "Id": "c8fb08d89c385ff722af56854930caba442a3f29ebde70aaf5aa495b3245ad29",
               "Name": "71003c6f9617-infra",
               "State": "configured"
          }
     ]
}

[root@dlp ~]#
podman images

REPOSITORY                         TAG     IMAGE ID      CREATED        SIZE
srv.world/fedora-nginx             latest  ef4fd3a3964f  3 seconds ago  425 MB
registry.fedoraproject.org/fedora  latest  5f05951e2065  2 weeks ago    187 MB
docker.io/library/mariadb          latest  992bce5ed710  2 weeks ago    407 MB
k8s.gcr.io/pause                   3.5     ed210e3e4a5b  8 weeks ago    690 kB

# run container and add it to pod

[root@dlp ~]#
podman run -dt --pod test-pod srv.world/fedora-nginx

034a8fb9384ccd61f1a78027dced9a702b0deae74f61bf40021b75a43bfa0804

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED        STATUS            PORTS                 NAMES
c8fb08d89c38  k8s.gcr.io/pause:3.5                                 4 minutes ago  Up 7 seconds ago  0.0.0.0:8081->80/tcp  71003c6f9617-infra
034a8fb9384c  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  6 seconds ago  Up 7 seconds ago  0.0.0.0:8081->80/tcp  hopeful_bartik

# verify accesses

[root@dlp ~]#
curl localhost:8081

Podman Test on Nginx
# stop pod

[root@dlp ~]#
podman pod stop test-pod

71003c6f96171c46c9619eba56be3238c33186bc66b9d4fd8fea551cda113e35

# remove pod (removed containers all)

[root@dlp ~]#
podman pod rm test-pod --force

71003c6f96171c46c9619eba56be3238c33186bc66b9d4fd8fea551cda113e35
[2] It's possbile to create Pod and add Container with one command.
[root@dlp ~]#
podman images

REPOSITORY                         TAG     IMAGE ID      CREATED             SIZE
srv.world/fedora-nginx             latest  ef4fd3a3964f  About a minute ago  425 MB
registry.fedoraproject.org/fedora  latest  5f05951e2065  2 weeks ago         187 MB
docker.io/library/mariadb          latest  992bce5ed710  2 weeks ago         407 MB
k8s.gcr.io/pause                   3.5     ed210e3e4a5b  8 weeks ago         690 kB

# create a [test-pod2] pod and add [srv.world/fedora-nginx] container

[root@dlp ~]#
podman run -dt --pod new:test-pod2 -p 80:80 -p 3306:3306 srv.world/fedora-nginx

9c9a53ba729fdd097bb91cba22d8a8b4a5590c9bbf2d669f8aed7668b0a77fdb

[root@dlp ~]#
podman pod ls

POD ID        NAME       STATUS   CREATED         INFRA ID      # OF CONTAINERS
30f8c1756117  test-pod2  Running  16 seconds ago  d495a8abb00e  2

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                          COMMAND               CREATED         STATUS             PORTS                                       NAMES
d495a8abb00e  k8s.gcr.io/pause:3.5                                 26 seconds ago  Up 26 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  30f8c1756117-infra
9c9a53ba729f  srv.world/fedora-nginx:latest  /usr/sbin/nginx -...  26 seconds ago  Up 26 seconds ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  unruffled_murdock

# run [mariadb] container and add it to the [test-pod2]

[root@dlp ~]#
podman run -dt --pod test-pod2 -e MYSQL_ROOT_PASSWORD=Password docker.io/library/mariadb

13993b796a3e54b26e130b989c8e08e12b5c59bb8dde2dbca9a1ed7fd32b9430

[root@dlp ~]#
podman ps

CONTAINER ID  IMAGE                             COMMAND               CREATED             STATUS                 PORTS                                       NAMES
d495a8abb00e  k8s.gcr.io/pause:3.5                                    About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  30f8c1756117-infra
9c9a53ba729f  srv.world/fedora-nginx:latest     /usr/sbin/nginx -...  About a minute ago  Up About a minute ago  0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  unruffled_murdock
13993b796a3e  docker.io/library/mariadb:latest  mysqld                14 seconds ago      Up 14 seconds ago      0.0.0.0:80->80/tcp, 0.0.0.0:3306->3306/tcp  romantic_mayer

[root@dlp ~]#
curl dlp.srv.world

Dockerfile Test on Nginx
[root@dlp ~]#
mysql -u root -p -h dlp.srv.world -e "show variables like 'hostname';"

Enter password:
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| hostname      | test-pod2 |
+---------------+-----------+
Matched Content