我部署了一个舵图(helm install --name=my-release stable/kube-ops-view
),该图通过clusterIP创建了一个svc,我试图通过traefik入口创建到它的路由,但是它不起作用
我已经能够使用类似的入口配置路由其他应用程序(nginx)
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo-ingress
namespace: kube-ops-view #svc is created in this namespace
spec:
rules:
- host:
http:
paths:
- path: /kube
backend:
serviceName: kube-ops-view
servicePort: 80
入口应该起作用
答案 0 :(得分:0)
我能够使其在GKE集群上运行。 创建集群后:
1)已安装头盔
2)已安装的NGINX入口控制器](https://kubernetes.github.io/ingress-nginx/deploy/)
下一步..
您应该将Rewrite target与nginx.ingress.kubernetes.io/rewrite-target
annotation结合使用。
从0.22.0版开始,使用注释进入定义 nginx.ingress.kubernetes.io/rewrite-target不向后 与以前的版本兼容。在0.22.0及更高版本中,任何 请求URI中需要传递给 重新编写的路径必须在捕获组中明确定义。
您的入口应该看起来像
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /$2
name: kubeops-kube-ops-view
namespace: default
spec:
rules:
- http:
paths:
- backend:
serviceName: kubeops-kube-ops-view
servicePort: 80
path: /kube(/?|$)(.*)
还有另一个选择:您可以在舵图中启用入口,而无需编写入口Yaml。
我的方式:
helm fetch stable/kube-ops-view --untar
编辑values.yaml
ingress:
enabled: true
path: /kube(/|$)(.*)
# hostname: kube-ops-view.local
annotations: {
kubernetes.io/ingress.class: nginx,
nginx.ingress.kubernetes.io/rewrite-target: /$2
}
tls: []
## Secrets must be manually created in the namespace
# - secretName: kube-ops-view.local-tls
# hosts:
# - kube-ops-view.local
编辑模板/ingress.yaml
{{- if .Values.ingress.enabled -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ template "kube-ops-view.fullname" . }}
labels:
app: {{ template "kube-ops-view.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- if .Values.ingress.annotations }}
annotations:
{{ toYaml .Values.ingress.annotations | indent 4 }}
{{- end }}
spec:
rules:
- host:
http:
paths:
- path: {{ .Values.ingress.path }}
backend:
serviceName: {{ template "kube-ops-view.fullname" . }}
servicePort: {{ .Values.service.externalPort }}
{{- if .Values.ingress.tls }}
tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end -}}
{{- end -}}
验证并安装: 掌舵安装--server-dry-run --debug kube-ops-view 头盔安装kube-ops-view --name kubeops
检查结果:
curl -iLk http://Ingress-external-ip/kube/
HTTP/1.1 308 Permanent Redirect
Server: openresty/1.15.8.1
Date: Thu, 22 Aug 2019 09:21:21 GMT
Content-Type: text/html
Content-Length: 177
Connection: keep-alive
Location: https://Ingress-external-ip/kube/
HTTP/2 200
server: openresty/1.15.8.1
date: Thu, 22 Aug 2019 09:21:21 GMT
content-type: text/html; charset=utf-8
content-length: 1276
vary: Accept-Encoding
strict-transport-security: max-age=15724800; includeSubDomains
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kubernetes Operational View 0.11</title>
<link rel="shortcut icon" href="static/favicon.ico">
<style>* {padding: 0; margin: 0} body { color: #aaaaff; background: #000; }</style>
<style>
/* latin */
@font-face {
font-family: 'ShareTechMono';
font-style: normal;
font-weight: 400;
/* ShareTechMono-Regular.ttf: Copyright (c) 2012, Carrois Type Design, Ralph du Carrois (www.carrois.com post@carrois.com), with Reserved Font Name 'Share'
License: SIL Open Font License, 1.1 */
src: local('Share Tech Mono'), local('ShareTechMono-Regular'), url(static/sharetechmono.woff2) format('woff2');
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000;
}
</style>
</head>
<body>
<!-- make sure the font is loaded -->
<div id="loading" style="font-family: ShareTechMono">Loading..</div>
<script src="static/build/app-ee71ac795470b05e7f76.js"></script>
<script>document.getElementById('loading').style.display = 'none'; const app = new App(); app.run()</script>
</body>
</html>