Ftps 服务器无法使用 kubernetes 正常工作

Ftps 服务器无法使用 kubernetes 正常工作

数周以来,我一直遇到 ftps-filezilla 和 Kubernetes 的问题。

语境

我有一个使用 Kubernetes 和 ftps 的学校项目。我需要在端口 21 的 kubernetes 中创建一个 ftps 服务器,并且它需要在 alpine linux 上运行。因此,我使用 docker 容器创建了我的 ftps-alpine 服务器的映像。我测试它,看它是否可以自行正常工作:使用docker run --name test-alpine -itp 21:21 test_alpine我在 filezilla 中有此输出:

    Status: Connecting to 192.168.99.100:21…
    Status: Connection established, waiting for welcome message…
    Status: Initializing TLS…
    Status: Verifying certificate…
    Status: TLS connection established.
    Status: Logged in
    Status: Retrieving directory listing…
    Status: Calculating timezone offset of server…
    Status: Timezone offset of server is 0 seconds.
    Status: Directory listing of “/” successful

它成功运行,filezilla 看到了我的 ftps 目录中的文件,现在我很好(在主动模式下工作)。

问题

所以我想要的是在我的 kubernetes 集群中使用我的镜像(我使用 Minikube)。当我将我的 docker 镜像连接到 kubernetes 中的 ingress-service-deployment 时,我得到了:

Status: Connecting to 192.168.99.100:30894...
Status: Connection established, waiting for welcome message...
Status: Initializing TLS...
Status: Verifying certificate...
Status: TLS connection established.
Status: Logged in
Status: Retrieving directory listing...
Command:    PWD
Response:   257 "/" is the current directory
Command:    TYPE I
Response:   200 Switching to Binary mode.
Command:    PASV
Response:   227 Entering Passive Mode (192,168,99,100,178,35).
Command:    LIST
Error:  The data connection could not be established: ECONNREFUSED - Connection refused by server

设置

ingress.yaml :

    kind: Ingress
    metadata:
    annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    namespace: default
    name: ingress-controller
    spec:
    backend:
    serviceName: my-nginx
    servicePort: 80
    backend:
    serviceName: ftps-alpine
    servicePort: 21

ftps-alpine.yml :

    apiVersion: v1
    kind: Service
    metadata:
    name: ftps-alpine
    labels:
    run: ftps-alpine
    spec:
    type: NodePort
    ports:

    port: 21
    targetPort: 21
    protocol: TCP
    name: ftp21
    port: 20
    targetPort: 20
    protocol: TCP
    name: ftp20
    selector:
    run: ftps-alpine
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: ftps-alpine
    spec:
    selector:
    matchLabels:
    run: ftps-alpine
    replicas: 1
    template:
    metadata:
    labels:
    run: ftps-alpine
    spec:
    - name: ftps-alpine
    image: test_alpine
    imagePullPolicy: Never
    ports:
    - containerPort: 21
    - containerPort: 20

我尝试了什么

vftpd.conf

    seccomp_sandbox=NO
    pasv_promiscuous=NO
    listen=NO
    listen_ipv6=YES
    anonymous_enable=NO
    local_enable=YES
    write_enable=YES
    local_umask=022
    dirmessage_enable=YES
    use_localtime=YES
    xferlog_enable=YES
    connect_from_port_20=YES
    chroot_local_user=YES
    #secure_chroot_dir=/vsftpd/empty
    pam_service_name=vsftpd
    pasv_enable=YES
    pasv_min_port=20
    pasv_max_port=20
    user_sub_token=$USER
    local_root=/home/$USER/ftp
    userlist_enable=YES
    userlist_file=/etc/vsftpd.userlist
    userlist_deny=NO
    rsa_cert_file=/etc/ssl/private/vsftpd.pem
    rsa_private_key_file=/etc/ssl/private/vsftpd.pem
    ssl_enable=YES
    allow_anon_ssl=NO
    force_local_data_ssl=YES
    force_local_logins_ssl=YES
    ssl_tlsv1=YES
    ssl_sslv2=NO
    ssl_sslv3=NO
    allow_writeable_chroot=YES
    #listen_port=21
    pasv_address=192.168.99.100
  1. 将 pasv_min 和最大端口从 20 更改为 20、从 20 更改为 21 以及从 30000 更改为 34000(nodeport 范围)。
  2. Listen=YES 和 Listen_ipv6=NO 等等。
  3. 我确实尝试了被动模式和主动模式。
  4. 我已将 pasv_address 设置为我的 minikube ip。

这是我在 stackoverflow 上提出的问题:https://stackoverflow.com/questions/60458028/ftps-server-doesnt-work-properly-using-kubernetes

问题

除了我的 kubernetes 集群,我怎样才能成功获取第一条消息?

如果您有任何疑问需要澄清,没问题。

答案1

经过以下更改后,它可以正常工作:

apiVersion: v1
    kind: Service
    metadata:
      name: ftps-alpine
      labels:
        run: ftps-alpine
    spec:
      type: NodePort
      ports:
      - port: 21
        targetPort: 21
        nodePort: 30025
        protocol: TCP
        name: ftp21
      - port: 20
        targetPort: 20
        protocol: TCP
        nodePort: 30026
        name: ftp20
      - port: 30020
        targetPort: 30020
        nodePort: 30020
        protocol: TCP
        name: ftp30020
      - port: 30021
        targetPort: 30021
        nodePort: 30021
        protocol: TCP
        name: ftp30021
      selector:
        run: ftps-alpine
    ---

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: ftps-alpine
    spec:
      selector:
        matchLabels:
          run: ftps-alpine
      replicas: 1
      template:
        metadata:
          labels:
            run: ftps-alpine
        spec:
          containers:
          - name: ftps-alpine
            image: test_alpine
            imagePullPolicy: Never
            ports:
            - containerPort: 21
            - containerPort: 20
            - containerPort: 30020
            - containerPort: 30021

对于 vsftpd.conf :

seccomp_sandbox=NO
pasv_promiscuous=NO
listen=YES
listen_ipv6=NO
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=YES
chroot_local_user=YES
#secure_chroot_dir=/vsftpd/empty
pam_service_name=vsftpd
pasv_enable=YES
pasv_min_port=30020
pasv_max_port=30021
user_sub_token=$USER
local_root=/home/$USER/ftp
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
rsa_cert_file=/etc/ssl/private/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.pem
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
allow_writeable_chroot=YES
#listen_port=21
pasv_address=#minikube_ip#

相关内容