使用 WLS2 在 Docker 桌面上启用入口控制器 [英] Enable Ingress controller on Docker Desktop with WLS2

查看:19
本文介绍了使用 WLS2 在 Docker 桌面上启用入口控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我使用带有 WSL2 集成的 Docker 桌面.我发现 Docker Desktop 自动为我创建了一个集群.这意味着我不必安装和使用 MinikubeKind 来创建集群.问题是,如果我使用内置"控制器,我如何启用 Ingress Controller从 Docker 桌面集群?我尝试创建一个 Ingress 来检查它是否有效,但据我猜测,它没有用.

Currently, I'm using Docker Desktop with WSL2 integration. I found that Docker Desktop automatically had created a cluster for me. It means I don't have to install and use Minikube or Kind to create cluster. The problem is that, how could I enable Ingress Controller if I use "built-in" cluster from Docker Desktop? I tried to create an Ingress to check if this work or not, but as my guess, it didn't work.

我创建的YAML文件如下:

The YAML file I created as follows:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp
spec:
  minReadySeconds: 30
  selector:
    matchLabels:
      app: webapp
  replicas: 1
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        image: nodejs-helloworld:v1

--- 

apiVersion: v1
kind: Service
metadata:
  name: webapp-service

spec:
  selector: 
    app: webapp
  
  ports:
    - name: http
      port: 3000
      nodePort: 30090 # only for NotPort > 30,000
    
  type: NodePort #ClusterIP inside cluster

---

apiVersion: networking.k8s.io/v1
kind: Ingress 
metadata:
  name: webapp-ingress
spec:
  defaultBackend:
    service:
      name: webapp-service
      port:
        number: 3000
  rules:
  - host: ingress.local
    http:
      paths:
      - path: / 
        pathType: Prefix
        backend:
          service:
            name:  webapp-service
            port: 
              number: 3000
    

我尝试访问 ingress.local/ 但没有成功.(我添加了 ingress.local 以指向主机文件中的 127.0.0.1.webappkubernetes.docker.internal:30090 上运行良好)

I tried to access ingress.local/ but it was not successful. (I added ingress.local to point to 127.0.0.1 in host file. And the webapp worked fine at kubernetes.docker.internal:30090 )

你能帮我知道根本原因吗?谢谢.

Could you please help me to know the root cause? Thank you.

推荐答案

我终于找到了解决方法.我必须通过命令部署 ingress Nginx:

Finally I found the way to fix. I have to deploy ingress Nginx by command:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/cloud/deploy.yaml

(按照 https://kubernetes.github 上的说明进行操作.io/ingress-nginx/deploy/#docker-for-mac.它适用于 Windows 的 Docker)

(Follows the instruction at https://kubernetes.github.io/ingress-nginx/deploy/#docker-for-mac. It works just fine for Docker for Windows)

现在我可以成功访问http://ingress.local.

这篇关于使用 WLS2 在 Docker 桌面上启用入口控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆