我试图在我的本地kubernetes (Docker-Desktop)中部署一个简单的nginx入口对象,但我注意到类名显示为"none">
➜ localk8 k get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-resource none * localhost 80 15m
我的入口定义文件定义为:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-resource
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /hello
pathType: Prefix
backend:
service:
name: hello-app
port:
number: 8080
我也在一台M1 macbook上运行,如果这有什么不同的话。谢谢大家的帮助!
我不确定您使用的是哪个版本的kubernetes,但是该注释在1.18中已弃用。
另外,您需要定义一个描述类的IngressClass
资源,然后使用新字段ingressClassName
:
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: nginx
spec:
controller: example.com/ingress-controller
然后在你进入资源添加新字段在规范和参考类名:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-resource
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
// use new field
ingressClassName: nginx
rules:
- http:
paths:
- path: /hello
pathType: Prefix
backend:
service:
name: hello-app
port:
number: 8080