網站首頁 編程語言 正文
一、Ingress介紹
Ingress由兩部分組成:Ingress controller和Ingress服務
- 通過 Service 發現 Pod 進行關聯。基于域名訪問
- 通過 Ingress Controller 實現 Pod 負載均衡
- 支持 TCP/UDP 4 層負載均衡和 HTTP 7 層負載均衡
底層實現是nignx
二、Ingress文件獲取
1.1 、說明
官方地址:https://github.com/kubernetes/ingress-nginx
部署文件說明
## 這個地址被墻,需要科學上網!!! # 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對外提供服務,注意默認nodeport暴露端口為隨機,可以編輯該文件自定義端口 wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/service-nodeport.yaml
1.2 、文件內容
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應用 ingress-controller.yaml
應用
kubectl apply -f ingress-controller.yaml
如圖:
查看是否完成
kubectl get pods --all-namespaces
四、創建Ingress規則
如果沒有部署和服務
==>查看k8s部署并映射tomcat8
查看自己創建的服務,以tomcat8為例
kubectl get all
自己創建文件 ingress-tomcat8.yaml
vi ingress-tomcat8.yaml
ingress-tomcat8.yaml規則內容
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: web spec: rules: - host: k8s.tomcat8.com http: paths: - backend: serviceName: tomcat8 servicePort: 80
如圖:
五、應用文件
kubectl apply -f ingress-tomcat8.yaml
六、訪問
1.本地測試用域名會訪問不到,所以要配置下本地hosts文件
hosts文件位置:C:\Windows\System32\drivers\etc\HOSTS
如圖:
不帶端口訪問,直接使用域名
使用ip端口訪問的效果
原文鏈接:https://blog.csdn.net/qq_44413835/article/details/123763974
相關推薦
- 2022-04-16 python中defaultdict字典功能特性介紹_python
- 2022-07-24 詳解Flutter中StatefulBuilder組件的使用_Android
- 2022-12-08 Python中的pandas庫簡介及其使用教程_python
- 2022-04-01 maven的settings.xml文件中配置多個nexus倉庫
- 2022-07-19 字符數組,字符串及其操作函數,指針
- 2022-12-23 C++中類的成員函數及內聯函數使用及說明_C 語言
- 2022-09-21 Flask深入了解Jinja2引擎的用法_python
- 2022-03-22 C++計算圓形、矩形和三角形的面積_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支