如何使用kind和docker访问windows中kubernetes的https 443端口

kqlmhetl  于 2023-03-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(265)

kubectl port-forward service/nginx 8080:443

Forwarding from 127.0.0.1:8080 -> 443
Forwarding from [::1]:8080 -> 443
Handling connection for 8080
E0314 16:38:47.834517   25527 portforward.go:406] an error occurred forwarding 8080 -> 443: error forwarding port 443 to pod bb5e0e3b270881ce659aa820d29dd47170e229abb90fb128e255467a8dba606a, uid : failed to execute portforward in network namespace "/var/run/netns/cni-5ef7f945-3c15-25c0-8540-39513d9d3285": failed to connect to localhost:443 inside namespace "bb5e0e3b270881ce659aa820d29dd47170e229abb90fb128e255467a8dba606a", IPv4: dial tcp4 **127.0.0.1:443: connect: connection refused IPv6 dial tcp6 [::1]:443: connect: connection refused
E0314 16:38:47.834846   25527 portforward.go:234] lost connection to pod**

the same working with port 80

c2e8gylq

c2e8gylq1#

使用的命令如下所示:

kubectl port-forward pod/<pod-name> <local-port>:<exposed-port>

其中,local-port是从浏览器访问容器的端口,而exposed-port是容器侦听的端口,该端口是使用Dockerfile中的EXPOSE命令定义的。
错误failed to connect to localhost:443类似于没有进程侦听端口443。用于创建nginx映像的dockerfile公开端口80,并且nginx被配置为默认侦听端口80
为了使用端口443建立连接,请更改ngnix配置文件以侦听端口443而不是端口80。另外,请使用相应的更改更新Docker映像。
由于您尚未共享nginx配置文件,因此默认的nginx.conf文件将如下所示:

server { 
    listen  ${PORT}; 
    server_name localhost;
 
    location / { 
        root   /usr/share/nginx/html; 
        index index.html index.htm; 
    } 

    include /etc/nginx/extra-conf.d/*.conf; 
}

请将上述模板中的**{PORT}更新为443**,并在DockerFile中添加以下行:

COPY ./nginx.conf /etc/nginx/conf.d/default.conf

有关更多详细信息,请参阅以下文档:
Link_1Link_2

相关问题