k8s部署Ingress并創(chuàng)建規(guī)則的詳細(xì)介紹
一、Ingress介紹
Ingress由兩部分組成:Ingress controller和Ingress服務(wù)
- 通過 Service 發(fā)現(xiàn) Pod 進行關(guān)聯(lián)?;谟蛎L問
- 通過 Ingress Controller 實現(xiàn) Pod 負(fù)載均衡
- 支持 TCP/UDP 4 層負(fù)載均衡和 HTTP 7 層負(fù)載均衡
底層實現(xiàn)是nignx
二、Ingress文件獲取
1.1 、說明
官方地址:https://github.com/kubernetes/ingress-nginx
部署文件說明
## 這個地址被墻,需要科學(xué)上網(wǎng)?。?! # mandatory.yaml為ingress所有資源yml文件的集合 # 若是單獨部署,需要分別下載configmap.yaml、namespace.yaml、rbac.yaml、service-nodeport.yaml、with-rbac.yaml wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml # service-nodeport.yaml為ingress通過nodeport對外提供服務(wù),注意默認(rèn)nodeport暴露端口為隨機,可以編輯該文件自定義端口 wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/service-nodeport.yaml
1.2 、文件內(nèi)容
ingress-controller.yaml
apiVersion: v1 kind: Namespace metadata: name: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx --- kind: ConfigMap name: nginx-configuration namespace: ingress-nginx name: tcp-services name: udp-services kind: ServiceAccount name: nginx-ingress-serviceaccount apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole name: nginx-ingress-clusterrole rules: - apiGroups: - "" resources: - configmaps - endpoints - nodes - pods - secrets verbs: - list - watch - get - services - "extensions" - ingresses - events - create - patch - ingresses/status - update kind: Role name: nginx-ingress-role - namespaces resourceNames: # Defaults to "<election-id>-<ingress-class>" # Here: "<ingress-controller-leader>-<nginx>" # This has to be adapted if you change either parameter # when launching the nginx-ingress-controller. - "ingress-controller-leader-nginx" kind: RoleBinding name: nginx-ingress-role-nisa-binding roleRef: apiGroup: rbac.authorization.k8s.io kind: Role subjects: - kind: ServiceAccount name: nginx-ingress-serviceaccount namespace: ingress-nginx kind: ClusterRoleBinding name: nginx-ingress-clusterrole-nisa-binding kind: ClusterRole apiVersion: apps/v1 kind: DaemonSet name: nginx-ingress-controller spec: selector: matchLabels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx template: metadata: labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx annotations: prometheus.io/port: "10254" prometheus.io/scrape: "true" spec: hostNetwork: true serviceAccountName: nginx-ingress-serviceaccount containers: - name: nginx-ingress-controller image: siriuszg/nginx-ingress-controller:0.20.0 args: - /nginx-ingress-controller - --configmap=$(POD_NAMESPACE)/nginx-configuration - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services - --udp-services-configmap=$(POD_NAMESPACE)/udp-services - --publish-service=$(POD_NAMESPACE)/ingress-nginx - --annotations-prefix=nginx.ingress.kubernetes.io securityContext: allowPrivilegeEscalation: true capabilities: drop: - ALL add: - NET_BIND_SERVICE # www-data -> 33 runAsUser: 33 env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE fieldPath: metadata.namespace ports: - name: http containerPort: 80 - name: https containerPort: 443 livenessProbe: failureThreshold: 3 httpGet: path: /healthz port: 10254 scheme: HTTP initialDelaySeconds: 10 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 10 readinessProbe: kind: Service #type: NodePort ports: - name: http port: 80 targetPort: 80 protocol: TCP - name: https port: 443 targetPort: 443
三、k8s應(yīng)用 ingress-controller.yaml
應(yīng)用
kubectl apply -f ingress-controller.yaml
如圖:
查看是否完成
kubectl get pods --all-namespaces
四、創(chuàng)建Ingress規(guī)則
如果沒有部署和服務(wù)
==>查看k8s部署并映射tomcat8
查看自己創(chuàng)建的服務(wù),以tomcat8為例
kubectl get all
自己創(chuàng)建文件 ingress-tomcat8.yaml
vi ingress-tomcat8.yaml
ingress-tomcat8.yaml規(guī)則內(nèi)容
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: web spec: rules: - host: k8s.tomcat8.com http: paths: - backend: serviceName: tomcat8 servicePort: 80
如圖:
五、應(yīng)用文件
kubectl apply -f ingress-tomcat8.yaml
六、訪問
1.本地測試用域名會訪問不到,所以要配置下本地hosts文件
hosts文件位置:C:\Windows\System32\drivers\etc\HOSTS
如圖:
不帶端口訪問,直接使用域名
使用ip端口訪問的效果
到此這篇關(guān)于k8s部署Ingress并創(chuàng)建規(guī)則的文章就介紹到這了,更多相關(guān)k8s部署Ingress內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Istio 自動注入 sidecar 失敗導(dǎo)致無法訪問webhook服務(wù)的解決方法
最近工作中在部署Istio環(huán)境的過程中發(fā)現(xiàn)官方示例啟動的pod不能訪問不到Istio的webhook,這個問題也是困擾了我一天,我把他歸類到sidecar注入失敗的情況下,本文給大家分享問題解決方法,感興趣的朋友跟隨小編一起看看吧2023-10-10Rainbond調(diào)用Vue?React項目的后端接口
這篇文章主要為大家介紹了Rainbond調(diào)用Vue?React項目的后端接口問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-04-04kubernetes k8s 存儲動態(tài)掛載配置詳解
這篇文章主要為大家介紹了kubernetes k8s 存儲動態(tài)掛載配置詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-11-11Kubernetes k8s configmap 容器技術(shù)解析
這篇文章主要為大家介紹了k8s configmap 容器技術(shù)解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08kubelet為cadvisor添加namespace/pod/container標(biāo)簽示例詳解
這篇文章主要為大家介紹了kubelet為cadvisor添加namespace/pod/container標(biāo)簽示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-09-09Rainbond自動部署初始化Schema的數(shù)據(jù)庫步驟教程
這篇文章主要為大家介紹了Rainbond自動部署初始化Schema的數(shù)據(jù)庫過程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-04-04CentOS 7.9 升級內(nèi)核 kernel-ml-5.6.14版本的方法
這篇文章主要介紹了CentOS 7.9 升級內(nèi)核 kernel-ml-5.6.14版本,默認(rèn)內(nèi)核版本為3.10.0,現(xiàn)升級到 5.6.14 版本,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-10-10