[英]Nginx ingress configuration for Kubernetes cluster hosted on windows
我通过 Docker 桌面在我的 windows PC 上运行 Kube.netes 集群。 我正在尝试使用简单的入口配置创建一个非常基本的 pod,但它似乎不起作用。 我认为后端 pod + 服务 + ingress 是一个非常基本的设置,但是我在网上找不到很多帮助。 请告知我在这里做错了什么。
我的deployment.yaml
文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
service.yaml
apiVersion: v1
kind: Service
metadata:
name: test-cluster-ip
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 1234
targetPort: 80
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /testpath
pathType: Exact
backend:
service:
name: test-cluster-ip
port:
number: 1234
这是我从浏览器访问本地主机时看到的
另外,我想问一下在 windows 上运行 Kube.netes 是否不常见,即使是为了测试(尤其是入口)。 我似乎没有在 inte.net 中找到很多示例。
我认为后端 pod + 服务 + ingress 是一个非常基本的设置,但是我在网上找不到很多帮助。 请告知我在这里做错了什么。
这确实是一个非常基本的设置。 并且您的 k8s deployment/service/ingress yaml 文件是正确的。
首先,检查你是否安装了NGINX ingress controller 。 如果没有,运行:
$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.1/deploy/static/provider/cloud/deploy.yaml
之后,您将能够使用以下 URL 访问 k8s 集群:
http://kubernetes.docker.internal/
但是像这样部署入口:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /testpath
pathType: Exact
backend:
service:
name: test-cluster-ip
port:
number: 1234
您正在配置入口以将/testpath
重写为/
。 在没有 /testpath 的情况下请求 url 将返回 404 状态代码。
在此处查看更多rewrite
示例。
因此,如果您使用以下 URL,您将从 k8s 部署中获得 Nginx 网页。
http://kubernetes.docker.internal/testpath
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.