我正在关注本教程:https://cloud.google.com/container-engine/docs/tutorials/http-balancer,但是在Minikube中运行它,每个步骤都有yml
个文件:
步骤1:部署nginx服务器
production.yml:
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: pwa-app-production
labels:
app: MyApp
spec:
replicas: 1
template:
metadata:
name: app
labels:
app: MyApp
env: production
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- name: nginx
containerPort: 80
然后:
$ kubectl apply -f production.yml
第2步:在内部将您的nginx部署作为服务公开
service.yml:
kind: Service
apiVersion: v1
metadata:
name: pwa-frontend
spec:
type: NodePort
selector:
app: MyApp
ports:
- name: nginx
port: 80
protocol: TCP
然后:
$ kubectl apply -f service.yml
验证是否已创建服务并已分配节点端口:
$ kubectl get service pwa-frontend
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
pwa-frontend 10.0.0.28 <nodes> 80:30781/TCP 26m
第3步:创建Ingress资源
ingress.yml:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: pwa-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
backend:
serviceName: pwa-frontend
servicePort: 80
然后:
$ kubectl create -f ingress.yml
第4步:访问您的申请
运行以下命令,找出为您的应用程序提供服务的负载均衡器的外部IP地址:
$ kubectl describe ing pwa-ingress
Name: pwa-ingress
Namespace: default
Address: 192.168.99.100
Default backend: pwa-frontend:80 (172.17.0.2:80)
Rules:
Host Path Backends
---- ---- --------
* * pwa-frontend:80 (172.17.0.2:80)
Annotations:
rewrite-target: /
每件事似乎运作良好,所有信息输出似乎都与教程相对应。但现在:
$ curl 192.168.99.100
default backend - 404
答案 0 :(得分:1)
我假设您通过minikube addons enable ingress
部署了默认的nginx入口控制器。您所遵循的教程专门针对Google容器引擎,在这些群集中,部署了不同的入口控制器,可以创建Google云负载均衡器,并且还能够公开纯TCP服务。 minikube中的nginx入口控制器只能处理这样的HTTP入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: pwa-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: pwa-frontend
servicePort: 80
修改文件后再次使用kubectl replace ingress.yml
并再次尝试使用您的请求。
答案 1 :(得分:0)
接受的答案在测试版时有点旧。这是更新的
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pwa-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: pwa-frontend
port:
number: 80