主机问题,使用 minikube + nginx ingress
Problem with host, with minikube + nginx ingress
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-depl
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: emotive44/auth
env:
- name: JWT_KEY
valueFrom:
secretKeyRef:
name: jwt-secret
key: JWT_KEY
---
apiVersion: v1
kind: Service
metadata:
name: auth-srv
spec:
type: NodePort
selector:
app: auth
ports:
- name: auth
protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30000
这是我的授权服务和部署。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: myapp.com
http:
paths:
- path: /api/users/?(.*)
pathType: "Prefix"
backend:
service:
name: auth-srv
port:
number: 3000
那是我的 Ingress 文件。
当我 运行 命令:minikube start
,我收到的消息是:
StartHost failed, but will try again: provision: get ssh host-port: get port 22 for "minikube": docker container inspect -f "'{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}'" minikube: exit status 1
kubectl get ingress
, returns:
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-service <none> myapp.com 192.168.49.2 80 106m
在我的 windows 主机文件中添加:192.168.49.2 myapp.com
如果我尝试在浏览器中打开 myapp.com:无法访问此网站
curl myapp.com
curl: (7) Failed to connect to myapp.com port 80: Timed out
这是我的入口描述:
Name: ingress-service
Namespace: default
Address: 192.168.49.2
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
myapp.com
/api/users/?(.*) auth-srv:3000 (172.17.0.2:3000)
Annotations: kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: true
可能是什么问题?
docker minikube 驱动程序的 known issues 说:
- The
ingress
, and ingress-dns
addons are currently only supported on Linux. See #7332
同样适用于Windows:
$ minikube addons enable ingress
* Due to docker networking limitations on windows, ingress addon is not supported for this driver.
Alternatively to use this addon you can use a vm-based driver:
'minikube start --vm=true'
To track the update on this work in progress feature please check:
https://github.com/kubernetes/minikube/issues/7332
解决方法是使用 hyperv driver:
Hyper-V is a native hypervisor built in to modern versions of
Microsoft Windows.
使用 --driver=hyperv
标志重新创建您的 minikube 集群将解决您的问题。
apiVersion: apps/v1
kind: Deployment
metadata:
name: auth-depl
spec:
replicas: 1
selector:
matchLabels:
app: auth
template:
metadata:
labels:
app: auth
spec:
containers:
- name: auth
image: emotive44/auth
env:
- name: JWT_KEY
valueFrom:
secretKeyRef:
name: jwt-secret
key: JWT_KEY
---
apiVersion: v1
kind: Service
metadata:
name: auth-srv
spec:
type: NodePort
selector:
app: auth
ports:
- name: auth
protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30000
这是我的授权服务和部署。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: myapp.com
http:
paths:
- path: /api/users/?(.*)
pathType: "Prefix"
backend:
service:
name: auth-srv
port:
number: 3000
那是我的 Ingress 文件。
当我 运行 命令:minikube start
,我收到的消息是:
StartHost failed, but will try again: provision: get ssh host-port: get port 22 for "minikube": docker container inspect -f "'{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}'" minikube: exit status 1
kubectl get ingress
, returns:
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-service <none> myapp.com 192.168.49.2 80 106m
在我的 windows 主机文件中添加:192.168.49.2 myapp.com
如果我尝试在浏览器中打开 myapp.com:无法访问此网站
curl myapp.com
curl: (7) Failed to connect to myapp.com port 80: Timed out
这是我的入口描述:
Name: ingress-service
Namespace: default
Address: 192.168.49.2
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
myapp.com
/api/users/?(.*) auth-srv:3000 (172.17.0.2:3000)
Annotations: kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: true
可能是什么问题?
docker minikube 驱动程序的 known issues 说:
- The
ingress
, andingress-dns
addons are currently only supported on Linux. See #7332
同样适用于Windows:
$ minikube addons enable ingress
* Due to docker networking limitations on windows, ingress addon is not supported for this driver.
Alternatively to use this addon you can use a vm-based driver:
'minikube start --vm=true'
To track the update on this work in progress feature please check:
https://github.com/kubernetes/minikube/issues/7332
解决方法是使用 hyperv driver:
Hyper-V is a native hypervisor built in to modern versions of Microsoft Windows.
使用 --driver=hyperv
标志重新创建您的 minikube 集群将解决您的问题。