https://blog.51cto.com/newfly/2060587
參考:https://cloud.tencent.com/developer/article/1490975
1.下載並執行了mandatory.yaml文件
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
2.下載https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/service-nodeport.yaml
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
上面的沒有安裝成功,故棄之。
參考:https://blog.51cto.com/hequan/2432608(主要參考)
https://www.cnblogs.com/cnmumian/p/10660207.html
https://blog.csdn.net/aixiaoyang168/article/details/81661459
1、下載mandatory.yaml
文件
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
出現了拒絕訪問:百度大概是缺少證書一類的吧,
先安裝:
ca-certificates
yum -y install ca-certificates
把命令改成 :
wget --no-check-certificate https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
於是下載成功。
2、執行命令 替換里面的,鏡像default-http的鏡像默認是google的鏡像地址,你懂得,所以替換成國內鏡像地址。
sed -i 's#quay.io/kubernetes-ingress-controller/nginx-ingress-controller#registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller#g' mandatory.yaml
mandatory.yaml文件內容比較多,在這里就不做展示。主要就是鏡像源需要找很久。
3、創建service-nodeport.yaml
文件,這里容易出錯的地方是pode的端口號,修改service文件,指定一下nodePort,使用80端口和443端口作為nodePort。
一般這個端口號會不在端口號的范圍內,也會出錯。所以需要自己去修改nodePort的范圍:https://blog.csdn.net/fuck487/article/details/102519225。或者將其修改為32080 和32443。
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
4、運行命令,生成一個叫ingress-nginx的namespace,以及一個叫ingress-nginx的service。
kubectl create -f mandatory.yaml
kubectl create -f service-nodeport.yaml
5、檢查生成狀態(這一步應該是mandatory.yaml
文件中的鏡像一直沒下載下來導致的。)
6、部署一個tomcat用於測試ingress轉發功能(也就是部署一個tomcat服務)
apiVersion: v1
kind: Service
metadata:
name: tomcat
namespace: default
spec:
selector:
app: tomcat
release: canary
ports:
- name: http
targetPort: 8080
port: 8080
- name: ajp
targetPort: 8009
port: 8009
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deploy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
release: canary
template:
metadata:
labels:
app: tomcat
release: canary
spec:
containers:
- name: tomcat
image: tomcat
ports:
- name: http
containerPort: 8080
7、