JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

ingress-nginx使用场景记录 nginx ingress部署与测试

wys521 2024-09-29 23:13:53 精选教程 38 ℃ 0 评论

ingress-nginx使用场景记录

一:查看ingress 规则

kubectl get ing -n metaverse

kubectl describe ingress home-web -n metaverse

二:错误记录

Q1:pod启动失败

kubectl logs -n ingress-nginx nginx-ingress-controller-967f8d8b4-xgrgp

https://kubernetes.github.io/ingress-nginx/troubleshooting/


Q2:Error from server (Forbidden): Forbidden (user=system:anonymous, verb=get, resource=nodes, subresource=proxy) ( pods/log nginx-ingress-controller-967f8d8b4-xgrgp)

临时处理

绑定一个cluster-admin的权限

kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous


这是一个RBAC错误。用户无权查看日志。如果您拥有具有群集管理员权限的用户,则可以使用此方法修复此错误

kubectl create clusterrolebinding the-boss --user system:anonymous --clusterrole cluster-admin

注意:提供匿名用户群集管理员角色不是一个好主意。但是会修复这个问题

三:http 跳转https

kind: Ingress

metadata:

通过添加下面的annotations 来开启白名单

关闭80强制跳转443 为ingress配置增加注解(annotations):nginx.ingress.kubernetes.io/ssl-redirect: 'false' 就可以禁止http强制跳转至https

annotations:

#nginx.ingress.kubernetes.io/whitelist-source-range: "60.191.70.64/29, xx.xxx.0.0/16"

nginx.ingress.kubernetes.io/ssl-redirect: 'false'

k8s路由默认http跳转到https, 用的是308跳转

四:ingress-nginx 部署

https://github.com/kubernetes/ingress-nginx

docker pull dyrnq/controller:v1.2.0

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1

修改deploy.yaml

修改镜像:

修改为:

docker.io/dyrnq/controller:v1.2.0

registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1

type: LoadBalancer

修改为

type: NodePort

dnsPolicy: ClusterFirst 下面增加

增加 hostNetwork: true,意思是开启主机网络模式,暴露 Nginx 服务端口 80 可以通过主机地址访问

hostNetwork: true

查看信息:

kubectl get svc,deploy,pods -n ingress-nginx


五:kube-webhook-certgen 介绍

自动生成webhook组件证书

在部署的时候需要生成访问webhook所需的证书

在组件中自动生成自签名证书,解决webhook部署时所需的证书问题

自签名证书生成镜像k8s.gcr.io/ingress-nginx/kube-webhook-certgen,现成的轮子,可以集成到helm的hook中,这样项目中的代码只需要根据配置中的secret生成服务器证书就行

https://github.com/bebc/webhook-tls

原理:https://cuisongliu.github.io/2020/07/kubernetes/admission-webhook/

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表