Trying phppgadmin docker container to view postgres database on host: it says login failed - postgresql

I want to view the host postgresql with phppgadmin docker container
My host is archlinux and with postgresql server running on it.
I have /var/lib/postgres/data/postgresql.conf
listen_addresses = "*"
and
/var/lib/postgres/data/pg_hba.conf
host all all 172.17.0.0/16 password
I want to view the postgresql tables. So i using phppgadmin docker with the following command
docker run --name='phppgadmin' --rm \
--publish=8888:80 \
-e PHP_PG_ADMIN_SERVER_HOST="127.0.0.1" \
dockage/phppgadmin:latest
Now i can open the phppgadmin from 127.0.0.1:8888/phppgadmin
But when i try to login it says login failed
I have a django project on my host using the using hosts postgresql. That works well with the settings
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': ‘<db_name>’,
'USER': '<db_username>',
'PASSWORD': '<password>',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
Also my netstat output on host
$ netstat -nrv
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 wlp3s0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-1c7e732767f4
172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-17604ffc4858
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp3s0
on my docker container
$ netstat -nrv
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

From netstat -nrv on my phppgadmin docker container
$ netstat -nrv
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.17.0.1 0.0.0.0 UG 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
So the ip address of the host is 172.17.0.1
Change PHP_PG_ADMIN_SERVER_HOST="127.0.0.1" to PHP_PG_ADMIN_SERVER_HOST="172.17.0.1"
docker run --name='phppgadmin' --rm \
--publish=8888:80 \
-e PHP_PG_ADMIN_SERVER_HOST="172.17.0.1" \
dockage/phppgadmin:latest
with:
I have /var/lib/postgres/data/postgresql.conf
listen_addresses = "localhost,127.0.0.1,172.17.0.1"
and
/var/lib/postgres/data/pg_hba.conf
host all all 172.17.0.0/16 md5
Open 127.0.0.1:8888/phppgadmin and login with non Superuser
For Superuser its still not working.

Related

kubernetes: can't ping pods

I created a k8s cluster which network configuration to pod is podSubnet: 172.168.0.0/12
Then, I find that can't ping those pod's IP.
for example, the deployment of metrics
# on k8s-master01 node:
$ kubectl get po -n kube-system -o wide
metrics-server-545b8b99c6-r2ql5 1/1 Running 0 5d1h 172.171.14.193 k8s-node02 <none> <none>
# ping 172.171.14.193 -c 2
PING 172.171.14.193 (172.171.14.193) 56(84) bytes of data.
^C
--- 172.171.14.193 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1016ms
# this is route table
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.180.104.1 0.0.0.0 UG 0 0 0 eth0
10.180.104.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.161.125.0 10.180.104.110 255.255.255.192 UG 0 0 0 tunl0
172.162.195.0 10.180.104.109 255.255.255.192 UG 0 0 0 tunl0
172.169.92.64 10.180.104.108 255.255.255.192 UG 0 0 0 tunl0
172.169.244.192 0.0.0.0 255.255.255.255 UH 0 0 0 cali06e1673851f
172.169.244.192 0.0.0.0 255.255.255.192 U 0 0 0 *
172.171.14.192 10.180.104.111 255.255.255.192 UG 0 0 0 tunl0
that shows metric pod host on k8s-node02. This is k8s-node02's route table
# route -n
Kernel IP routing table of k8s-master01
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.180.104.1 0.0.0.0 UG 0 0 0 eth0
10.180.104.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.169.254 10.180.104.11 255.255.255.255 UGH 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.161.125.0 10.180.104.110 255.255.255.192 UG 0 0 0 tunl0
172.162.195.0 10.180.104.109 255.255.255.192 UG 0 0 0 tunl0
172.169.92.64 10.180.104.108 255.255.255.192 UG 0 0 0 tunl0
172.169.244.192 10.180.104.107 255.255.255.192 UG 0 0 0 tunl0
172.171.14.192 0.0.0.0 255.255.255.192 U 0 0 0 *
172.171.14.193 0.0.0.0 255.255.255.255 UH 0 0 0 cali872eed170f4
172.171.14.194 0.0.0.0 255.255.255.255 UH 0 0 0 cali7d7625dd37e
172.171.14.203 0.0.0.0 255.255.255.255 UH 0 0 0 calid4e258f95f6
172.171.14.204 0.0.0.0 255.255.255.255 UH 0 0 0 cali5cf96eb1028
in fact, all pods can't access. I created a service based on example deployment.
# kubectl describe svc my-service
Name: my-service
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=demo-nginx
Type: ClusterIP
IP Families: <none>
IP: 10.100.75.139
IPs: 10.100.75.139
Port: http 80/TCP
TargetPort: 80/TCP
Endpoints: 172.161.125.14:80,172.161.125.15:80,172.171.14.203:80
Session Affinity: None
Events: <none>
# ping 10.100.75.139 -c 1
PING 10.100.75.139 (10.100.75.139) 56(84) bytes of data.
64 bytes from 10.100.75.139: icmp_seq=1 ttl=64 time=0.077 ms
# nc -vz 10.100.75.139 80
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connection timed out.
I suppose that the root cause is route table but not sure. Would you please help to fix this issue??
please feel free to let me know if you need more information.
Thanks a lot in advance.
BR//
In connect mode, Ncat initiates a connection (or sends UDP data) to a service that is listening somewhere. For those familiar with socket programming, connect mode is like using the connect function. In listen mode, Ncat waits for an incoming connection (or data receipt), like using the bind and listen to functions.
A connection timed out response indicates that your connection is not working, which could mean your firewall is blocking the port. Test the connection status by adding a rule that accepts connections on the required port.
There might be issues with traffic rules, try adding outbound traffic rules in security groups if you face the error again. Even after adding the traffic rules, if you face the same error then there must be some restricting rules on the node which is blocking you from accessing the port.
Refer to Testing Network services for more information.

Ping other pod in the same & different pod

I would like to ping B pod (node 1) from A pod (node 0) but it's unreachable. However, pinging pod in the same node can not be reachable too.
I am setting up new cluster for trying Kubernetes from Kelsey.
I have tried to use this link as my reference Kubernetes: Can't ping pods across nodes
Node - IP Private - IP Pod
worker-0 - 10.240.0.20 - 10.200.0.0/24
worker-1 - 10.240.0.21 - 10.200.1.0/24
worker-2 - 10.240.0.22 - 10.200.2.0/24
route -n
worker-0
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.240.0.1 0.0.0.0 UG 100 0 0 ens4
10.200.0.0 0.0.0.0 255.255.255.0 U 0 0 0 cnio0
10.240.0.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens4
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
worker-1
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.240.0.1 0.0.0.0 UG 100 0 0 ens4
10.200.1.0 0.0.0.0 255.255.255.0 U 0 0 0 cnio0
10.240.0.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens4
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
worker-2
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.240.0.1 0.0.0.0 UG 100 0 0 ens4
10.200.2.0 0.0.0.0 255.255.255.0 U 0 0 0 cnio0
10.240.0.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens4
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
I have done setting up VPC Netowrk Routes like this link.
After that i followed this reference Kubernetes: Can't ping pods across nodes
route add -net 10.200.1.0 netmask 255.255.255.0 gw 10.240.0.21 in worker-0
The result is
SIOCADDRT: Network is unreachable
I tried it in worker-0, worker-1, worker-2 and got same result.
Eventhough worker-0 can ping to worker-1 (10.240.0.21), reachable.
My expectation when i am in Pod A (worker-0) with IP Pod 10.200.0.3, i can ping to Pod B (worker-1) with IP Pod 10.200.1.3. And also, i can ping to Pod C (worker-0) same with Pod A.
Does this step should be using Calico or Flannel ? or Should we can ping other pod from different node without Calico or Flannel (only CNI setting) ?
Additional Information
I am using Docker not runc & containderd.
So, i installed Docker manually from this link.
In kubelet.service, --container-runtime=remote become --container-runtime=docker
Try adding the routes like this:
Worker-0:
$ sudo route add -net 10.200.1.0 netmask 255.255.255.0 gw 10.240.0.21
$ sudo route add -net 10.200.2.0 netmask 255.255.255.0 gw 10.240.0.22
Worker-1:
$ sudo route add -net 10.200.0.0 netmask 255.255.255.0 gw 10.240.0.20
$ sudo route add -net 10.200.2.0 netmask 255.255.255.0 gw 10.240.0.22
Worker-2:
$ sudo route add -net 10.200.0.0 netmask 255.255.255.0 gw 10.240.0.20
$ sudo route add -net 10.200.1.0 netmask 255.255.255.0 gw 10.240.0.21

minikube mount broken on VPN

So I'm having issues with minikube mount command while on Big-IP VPN. Basically, the command looks like it's able to ssh into the minikube VM, but for whatever reason, minikube can't mount the host folder.
$ minikube mount --v=10 app_shared_sec:/app/shared/sec
Mounting app_shared_sec into /app/shared/sec on the minikube VM
This daemon process needs to stay alive for the mount to still be accessible...
ufs starting
Using SSH client type: native
&{{{<nil> 0 [] [] []} docker [0x140f940] 0x140f910 [] 0s} 127.0.0.1 57930 <nil> <nil>}
About to run SSH command:
sudo umount /app/shared/sec;
SSH cmd err, output: Process exited with status 32: umount: /app/shared/sec: not mounted.
Using SSH client type: native
&{{{<nil> 0 [] [] []} docker [0x140f940] 0x140f910 [] 0s} 127.0.0.1 57930 <nil> <nil>}
About to run SSH command:
sudo mkdir -p /app/shared/sec || true;
sudo mount -t 9p -o trans=tcp,port=51501,dfltuid=1001,dfltgid=1001,version=9p2000.u,msize=262144 192.168.99.1 /app/shared/sec;
sudo chmod 775 /app/shared/sec || true;
SSH cmd err, output: <nil>: mount: /app/shared/sec: mount(2) system call failed: Connection timed out.
Running netstat within the minikube VM seems to point to it being able to read the host.
$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0
10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
10.0.2.2 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.99.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
The issue appears to be because VPN blows away the vboxnet interface on the host, minikube VM has no way of communicating with it, causing the mount to fail. When trying to re-create the route, Big-IP seems to watch for changes and removes it. Not sure what else to do at this point.

kubernetes : unable to join a node

I have created a master and am trying to join a node to create a cluster. When I try the join command I get the below error. Both the nodes are on the same network. The error message indicates that no routing exist to the host. I'm not sure how to establish a route to the host. Any help is appreciated.
sudo kubeadm join --token d23afe.14fde99cd03def7e 192.168.178.24:6443 --discovery-token-ca-cert-hash sha256:6a5e2674825e683bbdfe9bab512b03c556bcf89d8648317a64372bb44746bb39
[preflight] Running pre-flight checks.
[WARNING SystemVerification]: docker version is greater than the most recently validated version. Docker version: 18.02.0-ce. Max validated version: 17.03
[WARNING FileExisting-crictl]: crictl not found in system path
[discovery] Trying to connect to API Server "192.168.178.24:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.178.24:6443"
[discovery] Failed to request cluster info, will try again: [Get https://192.168.178.24:6443/api/v1/namespaces/kube-public/configmaps/cluster-info: dial tcp 192.168.178.24:6443: getsockopt: no route to host]
Here's the output of sudo route. Unfortunately, I have little knowledge to troubleshoot from this output
Here's the output of
`sudo route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.178.1 0.0.0.0 UG 202 0 0 eth0
10.32.0.0 0.0.0.0 255.240.0.0 U 0 0 0 weave
link-local 0.0.0.0 255.255.0.0 U 205 0 0 datapath
link-local 0.0.0.0 255.255.0.0 U 210 0 0 vethwe-datapath
link-local 0.0.0.0 255.255.0.0 U 211 0 0 vethwe-bridge
link-local 0.0.0.0 255.255.0.0 U 212 0 0 vxlan-6784
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.178.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0
`
I managed to identify the issue. The issue was with the weave net plugin. I did a tear down and reinstalled the plugin. I was then able to join the node. Thanks all for your suggestions.

Docker PostgreSQL service: could not bind IPv6 socket: Cannot assign requested address

I am running a PostgreSQL service with Docker. For some reason, PostgreSQL wants to bind to IPV6 - although I haven't specified that anywhere (at least as far as I'm aware).
As a result of this, I am unable to connect to PG. Relevant details follow below:
Dockerfile
FROM postgres:9.6
RUN apt-get update \
&& apt-get -y install apt-utils \
&& apt-get -y install python3 \
&& apt-get -y install postgresql-plpython3-9.6
COPY sql /docker-entrypoint-initdb.d/
EXPOSE 5432
# Add VOLUMEs to allow backup of config, logs and databases
VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]
PostgreSQL log file contents
LOG: received fast shutdown request
LOG: aborting any active transactions
waiting for server to shut down....LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
done
server stopped
PostgreSQL init process complete; ready for start up.
LOG: could not bind IPv6 socket: Cannot assign requested address
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: database system was shut down at 2017-10-09 21:22:22 UTC
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
I run the container using the following command: docker run --name my_db_service_cntnr image_tag
When I run the following command: docker container port my_db_service_cntnr, I get nothing returned:
me#yourbox:~/path/to/pgdb$ docker container port my_db_service_cntnr
me#yourbox:~/path/to/pgdb$
I know PostgreSQL is running in the container:
me#yourbox:~/path/to/pgdb$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
824ffe17c5b9 df:pg "docker-entrypoint..." 16 hours ago Up 5 minutes 5432/tcp my_db_service_cntnr
me#yourbox:/path/to/pgdb$ docker container inspect my_db_service_cntnr | grep Address
"LinkLocalIPv6Address": "",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"IPAddress": "172.17.0.2",
"MacAddress": "02:42:ac:11:00:02",
"IPAddress": "172.17.0.2",
"GlobalIPv6Address": "",
"MacAddress": "02:42:ac:11:00:02"
Yet when I attempt to connect to PostgreSQL (using default port of 5432), it fails to connect to the database:
Attempting to connect via psql
me#yourbox:~/path/to/pgdb$ psql -h 172.17.0.2 -U postgres -p 5432
psql: could not connect to server: Connection refused
Is the server running on host "172.17.0.2" and accepting
TCP/IP connections on port 5432?
me#yourbox:~/path/to/pgdb$
It seems port 5432 is not being listened to on my machine, despite me specifying that the PG image EXPOSE port 5432:
me#yourbox:~/path/to/pgdb$ sudo lsof -i -P | grep -i "listen"
lighttpd 1477 www-data 4u IPv4 22342 0t0 TCP *:80 (LISTEN)
dnsmasq 1645 nobody 5u IPv4 26954 0t0 TCP CEBERUS:53 (LISTEN)
master 2182 root 12u IPv4 28720 0t0 TCP localhost:25 (LISTEN)
master 2182 root 13u IPv6 28721 0t0 TCP ip6-localhost:25 (LISTEN)
rhythmbox 3149 me 17u IPv4 33925 0t0 TCP *:3689 (LISTEN)
rhythmbox 3149 me 18u IPv6 33926 0t0 TCP *:3689 (LISTEN)
cupsd 8432 root 10u IPv6 87004 0t0 TCP ip6-localhost:631 (LISTEN)
cupsd 8432 root 11u IPv4 87005 0t0 TCP localhost:631 (LISTEN)
What is causing this error, and how do I resolve it?
This isn't a complete answer, but should get you closer to an answer. It covers the dockerism's that are required for your debug steps in the question.
Run a postgres container
$ CID=$(docker run -d postgres)
$ echo $CID
48024dc71aa446...
Get the PID of the container
$ PID=$(docker inspect -f {{.State.Pid}} $CID)
$ echo $PID
7994
Get the logs from the container, check for errors.
$ docker logs $CID
Process list from the container
$ docker exec -ti $CID ps -ef
UID PID PPID C STIME TTY TIME CMD
postgres 1 0 0 23:19 ? 00:00:00 postgres
postgres 49 1 0 23:19 ? 00:00:00 postgres: checkpointer process
postgres 50 1 0 23:19 ? 00:00:00 postgres: writer process
postgres 51 1 0 23:19 ? 00:00:00 postgres: wal writer process
postgres 52 1 0 23:19 ? 00:00:00 postgres: autovacuum launcher pr
postgres 53 1 0 23:19 ? 00:00:00 postgres: stats collector proces
postgres 54 1 0 23:19 ? 00:00:00 postgres: bgworker: logical repl
root 66 0 0 23:26 ? 00:00:00 ps -ef
Run ss in the container looking for listening tcp processes (like lsof)
$ docker exec -ti $CID ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:5432 *:*
LISTEN 0 128 :::5432 :::*
Outside the container won't report on ports in container namespaces
$ ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:* users:(("sshd",pid=592,fd=3))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=592,fd=4))
From the host, you can use nsenter to enter the containers namespace and run commands.
$ nsenter -t $PID -n ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:5432 *:* users:(("postgres",pid=7994,fd=3))
LISTEN 0 128 :::5432 :::* users:(("postgres",pid=7994,fd=4))
$ nsenter -t $PID -n ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
52: eth0#if53: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 172.17.0.3/16 scope global eth0
valid_lft forever preferred_lft forever
Get the IP of the container from Docker
$ IP=$(docker inspect -f '{{.NetworkSettings.Networks.bridge.IPAddress}}' $CID)
$ echo $IP
172.17.0.3
Test the connection
$ psql -h $IP -U postgres -p 5432
Mapped ports
With a mapped port, the ports on the host changes slightly
$ CID=$(docker run -d -p 5432:5432 postgres)
$ echo $CID
020f72394fcd...
Now the container has a port configured
$ docker container port $CID
5432/tcp -> 0.0.0.0:5432
$ docker inspect -f {{.NetworkSettings.Ports}} $CID
map[5432/tcp:[{0.0.0.0 5432}]]
The port will also be listening on the host
$ ss -lntp
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:* users:(("sshd",pid=592,fd=3))
LISTEN 0 128 :::22 :::* users:(("sshd",pid=592,fd=4))
LISTEN 0 128 :::5432 :::* users:(("docker-proxy",pid=8571,fd=4))
And you can connect to localhost or your hosts IP now
$ psql -h 127.0.0.1 -U postgres -p 5432