Fedora 31
Sponsored Link

Podman : Create Pods2019/11/19

 
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

3349e0aaac57307380fa81fa80cd8e727f51cd7f6e1047b97541d3072784207e

# show pods

[root@dlp ~]#
podman pod ls

POD ID         NAME       STATUS    CREATED          # OF CONTAINERS   INFRA ID
3349e0aaac57   test_pod   Created   11 seconds ago   1                 c9a6bebd4f1b

# show details of pod

[root@dlp ~]#
podman pod inspect test_pod

{
     "Config": {
          "id": "3349e0aaac57307380fa81fa80cd8e727f51cd7f6e1047b97541d3072784207e",
          "name": "test_pod",
          "hostname": "test_pod",
          "labels": {

          },
          "cgroupParent": "machine.slice",
          "sharesCgroup": true,
          "sharesIpc": true,
          "sharesNet": true,
          "sharesUts": true,
          "infraConfig": {
               "makeInfraContainer": true,
               "infraPortBindings": [
                    {
                         "hostPort": 8081,
                         "containerPort": 80,
                         "protocol": "tcp",
                         "hostIP": ""
                    }
               ]
          },
          "created": "2019-11-18T17:27:32.918242268+09:00",
          "lockID": 11
     },
     "State": {
          "cgroupPath": "machine.slice/machine-libpod_pod_3349e0aaac57307380fa81fa80cd8e727f51cd7f6e1047b97541d3072784207e.slice",
          "infraContainerID": "c9a6bebd4f1b6feaf92a95ba409bd3503796559ba4b60bf7dcb9312fd66d31fd"
     },
     "Containers": [
          {
               "id": "c9a6bebd4f1b6feaf92a95ba409bd3503796559ba4b60bf7dcb9312fd66d31fd",
               "state": "configured"
          }
     ]
}

[root@dlp ~]#
podman images

REPOSITORY                        TAG      IMAGE ID       CREATED          SIZE
srv.world/nginx_server            latest   0311ace27400   31 minutes ago   991 MB
dlp.srv.world:5000/nginx_server   latest   0311ace27400   31 minutes ago   991 MB
srv.world/fedora_httpd            latest   bb6f86826d3f   38 minutes ago   622 MB
docker.io/library/fedora          latest   f0858ad3febd   2 weeks ago      201 MB
docker.io/library/registry        2        f32a97de94e1   8 months ago     26.4 MB
k8s.gcr.io/pause                  3.1      da86e6ba6ca1   23 months ago    747 kB

# run container and add it to pod

[root@dlp ~]#
podman run -dt --pod test_pod srv.world/nginx_server

a7630de75892e339a1b5b757d3a6023698cf712b28bd5de0dd759a692bdf85f2

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                            COMMAND               CREATED             STATUS                         PORTS                   NAMES
a7630de75892  srv.world/nginx_server:latest    /usr/sbin/nginx -...  9 seconds ago       Up 8 seconds ago               0.0.0.0:8081->80/tcp    vigilant_darwin
.....
.....

# verisy accesses

[root@dlp ~]#
curl localhost:8081

Podman Test on Nginx
# stop pod

[root@dlp ~]#
podman pod stop test_pod

3349e0aaac57307380fa81fa80cd8e727f51cd7f6e1047b97541d3072784207e

# remove pod (removed containers all)

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

3349e0aaac57307380fa81fa80cd8e727f51cd7f6e1047b97541d3072784207e
[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/nginx_server            latest   0311ace27400   32 minutes ago   991 MB
dlp.srv.world:5000/nginx_server   latest   0311ace27400   32 minutes ago   991 MB
srv.world/fedora_httpd            latest   bb6f86826d3f   39 minutes ago   622 MB
docker.io/library/fedora          latest   f0858ad3febd   2 weeks ago      201 MB
docker.io/library/registry        2        f32a97de94e1   8 months ago     26.4 MB
k8s.gcr.io/pause                  3.1      da86e6ba6ca1   23 months ago    747 kB

# create a [test_pod2] pod and run Container

[root@dlp ~]#
podman run -dt --pod new:test_pod2 -p 80:80 -p 3306:3306 srv.world/nginx_server

5209746a4575032bedf78ddd8ef53976cd3919aa205313ac5e85d7039830a3bb

[root@dlp ~]#
podman pod ls

POD ID         NAME        STATUS    CREATED         # OF CONTAINERS   INFRA ID
59d6939ba113   test_pod2   Running   9 seconds ago   2                 18c1eab24444

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                            COMMAND               CREATED         STATUS                     PORTS                   NAMES
5209746a4575  srv.world/nginx_server:latest    /usr/sbin/nginx -...  23 seconds ago  Up 23 seconds ago          0.0.0.0:80->80/tcp      stupefied_haibt
.....
.....

[root@dlp ~]#
podman run -dt --pod test_pod2 -e MYSQL_ROOT_PASSWORD=Password mariadb

e9879b44d1e6aa094aa46d114fd2d7f5822632de4b14f2dcfcd51d011c695340

[root@dlp ~]#
podman ps -a

CONTAINER ID  IMAGE                             COMMAND               CREATED             STATUS                     PORTS                   NAMES
e9879b44d1e6  docker.io/library/mariadb:latest  mysqld                15 seconds ago      Up 15 seconds ago          0.0.0.0:80->80/tcp      naughty_jang
5209746a4575  srv.world/nginx_server:latest     /usr/sbin/nginx -...  About a minute ago  Up About a minute ago      0.0.0.0:80->80/tcp      stupefied_haibt
18c1eab24444  k8s.gcr.io/pause:3.1                                    About a minute ago  Up About a minute ago      0.0.0.0:80->80/tcp      59d6939ba113-infra
.....
.....

[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