kubernetes安装ingress-nginx的步骤
系统版本:CentOs8.1
k8s版本:v1.21.3
containerd版本:ctr containerd.io 1.4.3
一: 准备yaml文件
github仓库地址:
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
以前用如上的地址下载,现在好像是不灵了
那我们选择ingress-nginx 0.20.0版本 https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0
下载 service-nodeport.yaml
https://github.com/kubernetes/ingress-nginx/blob/nginx-0.20.0/deploy/provider/baremetal/service-nodeport.yaml
下载 mandatory.yaml
https://github.com/kubernetes/ingress-nginx/blob/nginx-0.20.0/deploy/mandatory.yaml
将镜像地址替换为阿里可下载的地址(略)
#修改service-nodeport.yaml
vim service-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
protocol: TCP
nodePort: 32080 #http这里修改
- name: https
port: 443
targetPort: 443
protocol: TCP
nodePort: 32443 #https这里修改
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
部署
kubectl create namespace ingress-nginx
kubectl apply -f mandatory.yaml
kubectl apply -f service-nodeport.yaml
执行mandatory.yaml有异常报错
error: unable to recognize “mandatory.yaml”: no matches for kind “Deployment” in version “extensions/v1beta1”
解决方法, 修改mandatory.yarml文件
将apiVersion: extensions/v1beta1 修改成 apiVersion: apps/v1
再次执行
kubectl apply -f mandatory.yaml
正常
访问nodeport看看是否有返回信息
http://192.168.43.152:32080/
测试阶段
配置个服务
配置ingress
部署服务
查看ingress
[root@ck8s1 ingress]# kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress-csctbb csctbb.csctbb.com 80 22s
配置host访问
192.168.43.1 csctbb.csctbb.com
完成 !