IngressController
1. 安装
1.1 查看ingress-nginx的版本匹配
https://github.com/kubernetes/ingress-nginx/blob/main/README.md#readme
下载配置
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.2/deploy/static/provider/cloud/deploy.yaml
docker pull xyz349925756/ingress-nginx-controller:v1.0.5
查找出使用的镜像
grep image deploy.yaml
替换镜像为国内可以下载的镜像
原始:
image: k8s.gcr.io/ingress-nginx/controller:v1.1.2@sha256:0bc88eb15f9e7f84e8e56c14fa5735aaa488b840983f87bd79b1054190e660de
替换:
image: docker.io/liangjw/ingress-nginx-controller:v1.1.2
原始
image: k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1@sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660
替换
image: docker.io/liangjw/kube-webhook-certgen:v1.1.1
安装
kubectl apply -f deploy.yaml
2 使用NodeProt暴露
https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.1/deploy/static/provider/baremetal/deploy.yaml
3 使用HostProt的方式去暴露
先来给其中一个工作节点打一label
[root@node-2 ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
node-2 Ready <none> 29h v1.20.2
node-3 Ready <none> 29h v1.20.2
[root@node-2 ~]# kubectl label node node-3 app=ingress
node/node-3 labeled
修改Deployment下的配置,让其变成hostPost模式,且选择刚刚打标签的node部署
4 ingress demo
#deploy
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-demo
spec:
selector:
matchLabels:
app: tomcat-demo
replicas: 1
template:
metadata:
labels:
app: tomcat-demo
spec:
containers:
- name: tomcat-demo
image: registry.cn-hangzhou.aliyuncs.com/liuyi01/tomcat:8.0.51-alpine
ports:
- containerPort: 8080
---
#service
apiVersion: v1
kind: Service
metadata:
name: tomcat-demo
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: tomcat-demo
---
#ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tomcat-demo
spec:
ingressClassName: nginx
rules:
- host: tomcat.mooc.com
http:
paths:
- path: /
backend:
serviceName: tomcat-demo
servicePort: 80
新版本的ingress需要加上 ingressClassName
不然ingress无法发现服务
参考: https://blog.csdn.net/Hello_worId/article/details/123602379
先复制
vim ingress-demo.yaml
:set paste
insert
shift + insert
:wq
不出意外的出现了意外情况。
百度下发现是因为我装了好几次的ingress-controller,但是又没有把东西删干净
https://blog.csdn.net/qq_39218530/article/details/115372879
使用下面的命令查看 webhook
kubectl get validatingwebhookconfigurations
ingress-nginx-admission
删除ingress-nginx-admission
kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission