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

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

问题描述

当前,我正在使用具有 WSL2 集成的Docker桌面.我发现 Docker Desktop 为我自动创建了一个集群.这意味着我不必安装并使用 Minikube 种类来创建集群.问题是,如果我使用内置"功能,该如何启用 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. webapp kubernetes.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 .

Now I can access http://ingress.local successfully.

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

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