Skip to content

Instantly share code, notes, and snippets.

@tonejito
Last active June 22, 2023 19:44
Show Gist options
  • Save tonejito/f0c1b8377feab954e4797c443aea0df0 to your computer and use it in GitHub Desktop.
Save tonejito/f0c1b8377feab954e4797c443aea0df0 to your computer and use it in GitHub Desktop.

Iniciar servicio PostgreSQL con un contenedor en utility

Iniciar sesion en utility.

[student@workstation ~]$ ssh lab@utility
[lab@utility ~]$

Verificar las direcciones IP asignadas en utility.

[lab@utility ~]$ hostname -I
172.25.250.253 192.168.50.254 192.168.51.254 

Abrir el puerto 5432 de PostgreSQL en utility.

[lab@utility ~]$ sudo firewall-cmd --zone=external --permanent --add-service=postgresql
success

[lab@utility ~]$ sudo firewall-cmd --reload
success

Verificar la conectividad al registry en el puerto 8443.

[lab@utility ~]$ nc -vz registry.ocp4.example.com 8443
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.50.50:8443.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.

Iniciar sesion en el registry.

  • Se utiliza la opción --tls-verify=false porque el certificado no valida bien en utility
[lab@utility ~]$ podman login \
  --tls-verify=false \
  -u developer \
  -p developer \
  registry.ocp4.example.com:8443
Login Succeeded!

Ejecutar el contenedor de PostgreSQL en utility.

  • Se crea la carpeta /tmp/postgresql para que pueda ser persistente.
  • Se utiliza la opción --tls-verify=false porque el certificado no valida bien en utility.
  • Se utiliza la opción :Z al final del argumento -v para dar los atributos necesarios de SELinux en el contenedor.
  • Se utiliza la opción -it para probar que el contenedor levanta bien, ejecutar con -d para enviar a segundo plano.
  • Se puede cambiar la imagen a registry.ocp4.example.com:8443/rhel8/postgresql-10:1-215 que es la copia de registry.redhat.io/rhel8/postgresql-10:1-215 para evitar el mensaje de advertencia que lanza el cliente de PostgreSQL 10 al conecarse al servidor PostgreSQL 13.
[lab@utility ~]$ mkdir -vp /tmp/postgresql
mkdir: created directory '/tmp/postgresql'

[lab@utility ~]$ POSTGRES_IMAGE="registry.ocp4.example.com:8443/rhel8/postgresql-10:1-215"
[lab@utility ~]$ POSTGRES_IMAGE="registry.ocp4.example.com:8443/rhel8/postgresql-13:1-7"

[lab@utility ~]$ podman run
  --tls-verify=false \
  -it \
  --rm \
  --name=podman-postgresql \
  -v /tmp/postgresql:/var/lib/pgsql:Z \
  -p 5432:5432 \
  -e POSTGRESQL_USER=user \
  -e POSTGRESQL_PASSWORD=password \
  -e POSTGRESQL_DATABASE=database \
  ${POSTGRES_IMAGE}

Verificar las direcciones IP asignadas en utility.

[lab@utility ~]$ hostname -I
172.25.250.253 192.168.50.254 192.168.51.254 

Salir de la conexion SSH de utility.

[lab@utility ~]$ exit
[student@workstation ~]$

Probar la conexión de PostgreSQL de workstation a utility

Revisar a que IP resuelve el nombre DNS de utility.

[student@workstation ~]$ dig +short utility.lab.example.com
172.25.250.253

Verificar la conectividad al servicio de PostgreSQL en utility.

  • Probar con la primera IP 172.25.250.253
[student@workstation ~]$ nc -vz 172.25.250.253 5432
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connected to 172.25.250.253:5432.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.

[student@workstation ~]$ psql -U user -d database -h 172.25.250.253
Password for user user: 
psql (10.19, server 13.2)
WARNING: psql major version 10, server major version 13.
         Some psql features might not work.
Type "help" for help.

database=> \q
  • Probar con la segunda IP 192.168.50.254
[student@workstation ~]$ nc -vz 192.168.50.254 5432
Ncat: Version 7.70 ( https://nmap.org/ncat )
Ncat: Connected to 192.168.50.254:5432.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.

[student@workstation ~]$ psql -U user -d database -h 192.168.50.254
Password for user user: 
psql (10.19, server 13.2)
WARNING: psql major version 10, server major version 13.
         Some psql features might not work.
Type "help" for help.

database=> \q
  • La conexion no funciona con la IP 192.168.51.254

Eliminar el servicio de PostgreSQL en utility

Iniciar sesion en utility.

[student@workstation ~]$ ssh lab@utility
[lab@utility ~]$

Detener y eliminar el contenedor de PostgreSQL.

[lab@utility ~]$ podman kill podman-postgresql
...
[lab@utility ~]$ podman rm podman-postgresql
...

Eliminar el directorio /tmp/postgresql.

  • Se utiliza sudo porque se dieron permisos especiales al directorio.
[lab@utility ~]$ sudo rm -rf /tmp/postgresql
...

Notas

  • Se puede cambiar la imagen a registry.ocp4.example.com:8443/rhel8/postgresql-10:1-215 que es la copia de registry.redhat.io/rhel8/postgresql-10:1-215 para evitar el mensaje de advertencia que lanza el cliente de PostgreSQL 10 al conecarse al servidor PostgreSQL 13.
  • Utilice en este ejemplo la imagen registry.ocp4.example.com:8443/rhel8/postgresql-13:1-7 porque es la que estaba en el registry del classroom pero pedi que se agregara la imagen de Postgres 10.
psql (10.19, server 13.2)
WARNING: psql major version 10, server major version 13.
         Some psql features might not work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment