资料信息地址:
Ingress-Nginx-github 地址:https://github.com/kubernetes/ingress-nginx
Ingress-Nginx 官方地址:https://kubernetes.github.io/ingress-nginx
一、下载并修改配置文件
1、下载整合配置文件,获取配置文件地址:https://github.com/kubernetes/ingress-nginx/tree/nginx-0.20.0/deploy
2、修改配置文件
[root@k8s-master ingress]# cat mandatory.yaml |grep image ... # 修改defaultbackend镜像地址改成阿里云的镜像地址 image: registry.cn-qingdao.aliyuncs.com/kubernetes_xingej/defaultbackend-amd64:1.5 # 1、修改镜像地址为阿里云地址 ...
二、运行 Ingress 配置文件
# 1、修改并运行配置文件
[root@k8s-master ingress]# vi mandatory.yaml [root@k8s-master ingress]# kubectl apply -f mandatory.yaml namespace/ingress-nginx created deployment.extensions/default-http-backend created service/default-http-backend created configmap/nginx-configuration created configmap/tcp-services created configmap/udp-services created serviceaccount/nginx-ingress-serviceaccount created clusterrole.rbac.authorization.k8s.io/nginx-ingress-clusterrole created role.rbac.authorization.k8s.io/nginx-ingress-role created rolebinding.rbac.authorization.k8s.io/nginx-ingress-role-nisa-binding created clusterrolebinding.rbac.authorization.k8s.io/nginx-ingress-clusterrole-nisa-binding created deployment.extensions/nginx-ingress-controller created
# 2、查看运行结果 [root@k8s-master ingress]# kubectl get pods -n ingress-nginx -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES default-http-backend-5c9bb94849-9b4m4 1/1 Running 0 25h 10.244.1.36 k8s-node01 <none> <none> nginx-ingress-controller-84d5b54fdf-n4wgs 1/1 Running 0 25h 192.168.101.28 k8s-node02 <none> <none> [root@k8s-master ingress]#
三、书写并运行 Service 服务
[root@k8s-master ingress]# vi service-nodeport.yml 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
步骤如下
[root@k8s-master ingress]# vi service-nodeport.yml [root@k8s-master ingress]# kubectl apply -f service-nodeport.yml service/ingress-nginx created [root@k8s-master ingress]# kubectl get svc -n ingress-nginx NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default-http-backend ClusterIP 10.107.251.54 <none> 80/TCP 25h ingress-nginx NodePort 10.110.30.195 <none> 80:32080/TCP,443:32443/TCP 16s [root@k8s-master ingress]#
四、访问测试页面