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

问题描述 投票:0回答:2

我几个星期都对ftps-filezilla和Kubernetes遇到问题。

上下文

我有一个使用Kubernetes和ftps的学校项目。我需要在端口21的kubernetes中创建一个ftps服务器,并且它需要在高山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:    PORT 192,168,99,1,227,247
    Response:   500 Illegal PORT command.
    Command:    PASV
    Response:   227 Entering Passive Mode (172,17,0,5,117,69).
    Command:    LIST
    Error:  The data connection could not be established: EHOSTUNREACH - No route to host
    Error:  Connection timed out after 20 seconds of inactivity
    Error:  Failed to retrieve directory listing

SETUP


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

我尝试了什么

  • [当我看到错误消息:错误:数据连接无法将被建立:EHOSTUNREACH-没有路由来托管谷歌它,我看到了这条信息 :FTP in passive mode : EHOSTUNREACH - No route to host。而且我已经以主动模式运行ftps服务器。
  • 更改vsftpd.conf文件和我的服务:
vsftpd.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=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

我确实将kubernetes的nodeport更改为30020和30021,并将它们添加到容器端口。我更改了pasv最小端口和最大端口。我添加了我的minikube ip的pasv_adress。什么也没做。

问题

除了我的kubernetes集群外,我如何获得成功的第一条消息?

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

UPDATE

多亏了coderanger,我已经取得了进步,并且有这个问题:

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
docker kubernetes port ftps vsftpd
2个回答
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#

0
投票

首先,您需要将无源端口范围固定为实际上是在服务中设置的端口20:

pasv_min_port=20
pasv_max_port=20

然后您需要重写pasv_address以匹配用户应连接到的任何IP,选择您的节点IP之一。

© www.soinside.com 2019 - 2024. All rights reserved.