Ami*_*dav 1 sftp google-cloud-platform kubernetes google-kubernetes-engine kubernetes-ingress
使用 NodePort 服务和 Kubernetes Ingress 公开时,SFTP 服务器无法访问。但是,如果通过 LoadBalancer 服务公开相同的部署,则它可以正常工作。
以下是使用atmoz/sftp Dockerfile 在Google Kubernetes Engine中进行 SFTP 的部署文件。
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: sftp
labels:
environment: production
app: sftp
spec:
replicas: 1
minReadySeconds: 10
template:
metadata:
labels:
environment: production
app: sftp
annotations:
container.apparmor.security.beta.kubernetes.io/sftp: runtime/default
spec:
containers:
- name: sftp
image: atmoz/sftp:alpine
imagePullPolicy: Always
args: ["user:pass:1001:100:upload"]
ports:
- containerPort: 22
securityContext:
capabilities:
add: ["SYS_ADMIN"]
resources: {}
Run Code Online (Sandbox Code Playgroud)
如果我通常使用 LoadBalancer 类型的 Kubernetes 服务公开此部署,如下所示,此服务将获得一个外部 IP,我可以简单地在命令中使用该 IPsftp xxx.xx.xx.xxx来使用pass密码访问它。
apiVersion: v1
kind: Service
metadata:
labels:
environment: production
name: sftp-service
spec:
type: LoadBalancer
ports:
- name: sftp-port
port: 22
protocol: TCP
targetPort: 22
selector:
app: sftp
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用 Ingress 公开相同的部署时,它不起作用。
将外部 IP 分配给 Ingress 后(确认需要几分钟才能完全设置),xxx.xx.xx.xxx/sample开始工作,但sftp -P 80 xxx.xx.xx.xxx没有。
# First I create a NodePort service to expose the deployment internally
---
apiVersion: v1
kind: Service
metadata:
labels:
environment: production
name: sftp-service
spec:
type: NodePort
ports:
- name: sftp-port
port: 22
protocol: TCP
targetPort: 22
nodePort: 30063
selector:
app: sftp
# Ingress service has SFTP service as its default backend
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: basic-ingress-2
spec:
backend:
serviceName: sftp-service
servicePort: 22
rules:
- http:
paths:
# "http-service-sample" is a service exposing a simple hello-word app deployment
- path: /sample
backend:
serviceName: http-service-sample
servicePort: 80
Run Code Online (Sandbox Code Playgroud)
以下是我从服务器收到的错误:
ssh_exchange_identification: Connection closed by remote host
Connection closed
Run Code Online (Sandbox Code Playgroud)
我在上面的设置中做错了什么?为什么LoadBalancer服务能够允许访问SFTP服务,而Ingress却失败?
目前不完全支持在 Kubernetes Ingress 中路由除 HTTP/HTTPS 协议之外的任何其他流量(请参阅文档)。
您可以尝试按照此处所述进行一些解决方法:Kubernetes: Routing non HTTP Request via Ingress to Container
| 归档时间: |
|
| 查看次数: |
10111 次 |
| 最近记录: |