For testing purposes I'am running a pod (SSHFS container: port 22) mounted to a persistent disk.
I would like to be able to connect to it from outside, I succesfully created a pod and a service lb that maps container port 22 to outside 2222, but I am unable to connect to it from outside (Internet).
Below is the steps I undertook to build and troubleshoot it.
Any hint?
$ cat sshfs-server-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: sshfsserver
spec:
containers:
- image: ajnouri/sshfs-server
name: sshfsserver
ports:
- containerPort: 22
name: sshfs
volumeMounts:
- mountPath: /data
name: gns3-persistent-data
volumes:
- name: gns3-persistent-data
gcePersistentDisk:
pdName: gns3-data-disk1
fsType: ext4
$ cat sshfs-server-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: sshfsserver
name: sshfsserver
spec:
type: LoadBalancer
ports:
- port: 22
targetPort: 2222
protocol: TCP
selector:
name: sshfsserver
$ kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.51.240.1 443/TCP 1d
sshfsserver 10.51.248.10 35.196.251.4 2222:30550/TCP 25m
$ ping 35.196.251.4
PING 35.196.251.4 (35.196.251.4) 56(84) bytes of data.
64 bytes from 35.196.251.4: icmp_seq=1 ttl=42 time=89.9 ms
64 bytes from 35.196.251.4: icmp_seq=2 ttl=42 time=89.9 ms
64 bytes from 35.196.251.4: icmp_seq=3 ttl=42 time=89.8 ms
^C
--- 35.196.251.4 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 89.884/89.906/89.923/0.016 ms
Cannot connect to the container from outside (Internet host)
Even though I could verify that the container is running the sshd process and port 22 is opened and I could SSH to connect to the container from the cluster pod:
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
sshfsserver 1/1 Running 0 20h 10.48.0.10 gke-gns3-data-cluster1-default-pool-8754d417-s9tz
user@gke-gns3-data-cluster1-default-pool-8754d417-s9tz ~ $ docker exec aee37c04226a ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 29336 10976 ? Ss 02:39 0:00 /usr/bin/python3 -u /sbin/my_init
root 7 0.0 0.0 196 40 ? S 02:39 0:00 /usr/bin/runsvdir -P /etc/service
root 8 0.0 0.0 176 4 ? Ss 02:39 0:00 runsv cron
root 9 0.0 0.0 176 4 ? Ss 02:39 0:00 runsv syslog-ng
root 10 0.0 0.0 176 4 ? Ss 02:39 0:00 runsv sshd
root 11 0.0 0.0 176 4 ? Ss 02:39 0:00 runsv syslog-forwarder
root 12 0.0 0.0 7484 1852 ? S 02:39 0:04 tail -f -n 0 /var/log/syslog
root 13 0.0 0.1 61372 5420 ? S 02:39 0:00 /usr/sbin/sshd -D
root 14 0.0 0.1 65756 6796 ? S 02:39 0:00 syslog-ng -F -p /var/run/syslog-ng.pid --no-caps
root 15 0.0 0.0 18324 1820 ? S 02:39 0:00 /usr/sbin/cron -f
root 24 0.0 0.0 15576 2084 ? Rs 22:49 0:00 ps -aux
user@gke-gns3-data-cluster1-default-pool-8754d417-s9tz ~ $ docker exec aee37c04226a ip a s eth0@if13
3: eth0@if13: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue state UP group
default
link/ether 0a:58:0a:30:00:0a brd ff:ff:ff:ff:ff:ff
inet 10.48.0.10/24 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::4c5f:3fff:fe65:890d/64 scope link
valid_lft forever preferred_lft forever
user@gke-gns3-data-cluster1-default-pool-8754d417-s9tz ~ $ ssh [email protected]
Warning: Permanently added '10.48.0.10' (ECDSA) to the list of known hosts.
[email protected]'s password:
root@sshfsserver:~#