一、概述

Ingress 是对集群中服务的外部访问进行管理的 API 对象,可以提供负载均衡、SSL 终结和基于名称的虚拟托管。

典型的访问方式是 HTTP,用于将不同URL的访问请求转发到后端不同的 Service,以实现HTTP层的业务路由机制。

Kubernetes使用了一个Ingress策略定义和一个具体的 Ingress Controller,两者结合并实现了一个完整的Ingress负载均衡器。

使用Ingress进行负载分发时,Ingress Controller基于Ingress规则将客户端请求直接转发到Service对应的后端Endpoint(Pod)上,这样会跳过kube-proxy的转发功能,kube-proxy不再起作用。

Ingress 不会公开任意端口或协议。 将 HTTP 和 HTTPS 以外的服务公开到 Internet 时,通常使用 Service.Type=NodePort 或者 Service.Type=LoadBalancer 类型的服务。


二、常见控制器

Kubernetes Ingress 作为"官方"控制器,它是由社区基于NGINX Web服务器开发的,并补充了一组用于实现额外功能的Lua插件。

NGINX Ingress 这是NGINX开发人员的官方产品,NGINX控制器具有很高的稳定性,持续的向后兼容性,没有任何第三方模块,并且由于消除了Lua代码而保证了较高的速度(与官方控制器相比)。

Kong Ingress由Kong Inc开发,并且有两个版本:商业版本和免费版本。Kong Ingress建立在NGINX之上,并增加了扩展其功能的Lua模块。

HAProxy Ingress 由HAProxy开发,它提供了“软”配置更新(无流量丢失),基于DNS的服务发现,通过API的动态配置。

Traefik 是一个全功能的 ingress 控制器  (Let's Encrypt,secrets,http2,websocket),并且它也有来自 Containous 的商业支持。

Istio 是IBM,Google和Lyft(Envoy的原始作者)的联合项目,它是一个全面的服务网格解决方案。它不仅可以管理所有传入的外部流量(作为Ingress控制器),还可以控制集群内部的所有流量。

在幕后,Istio将Envoy用作每种服务的辅助代理。从本质上讲,它是一个可以执行几乎所有操作的大型处理器。其中心思想是最大程度的控制,可扩展性,安全性和透明性。

更多参考 >>> Kubernetes的Ingress控制器比较


三、推荐控制器

  1)  如果刚开始接触Ingress,项目并发和性能要求也不高,那我推荐使用官方的Ingress控制器。毕竟官方产品对k8s本身支持无可厚非,并且配置和部署都比较简单。

     ① 安装部署指导:https://kubernetes.github.io/ingress-nginx/deploy/

  1. kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/deploy.yaml

② 当然你也可以直接复制以下修改好的文件:

  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4. name: ingress-nginx
  5. labels:
  6. app.kubernetes.io/name: ingress-nginx
  7. app.kubernetes.io/instance: ingress-nginx
  8. ---
  9. # Source: ingress-nginx/templates/controller-serviceaccount.yaml
  10. apiVersion: v1
  11. kind: ServiceAccount
  12. metadata:
  13. labels:
  14. helm.sh/chart: ingress-nginx-2.0.3
  15. app.kubernetes.io/name: ingress-nginx
  16. app.kubernetes.io/instance: ingress-nginx
  17. app.kubernetes.io/version: 0.32.0
  18. app.kubernetes.io/managed-by: Helm
  19. app.kubernetes.io/component: controller
  20. name: ingress-nginx
  21. namespace: ingress-nginx
  22. ---
  23. # Source: ingress-nginx/templates/controller-configmap.yaml
  24. apiVersion: v1
  25. kind: ConfigMap
  26. metadata:
  27. labels:
  28. helm.sh/chart: ingress-nginx-2.0.3
  29. app.kubernetes.io/name: ingress-nginx
  30. app.kubernetes.io/instance: ingress-nginx
  31. app.kubernetes.io/version: 0.32.0
  32. app.kubernetes.io/managed-by: Helm
  33. app.kubernetes.io/component: controller
  34. name: ingress-nginx-controller
  35. namespace: ingress-nginx
  36. data:
  37. ---
  38. # Source: ingress-nginx/templates/clusterrole.yaml
  39. apiVersion: rbac.authorization.k8s.io/v1
  40. kind: ClusterRole
  41. metadata:
  42. labels:
  43. helm.sh/chart: ingress-nginx-2.0.3
  44. app.kubernetes.io/name: ingress-nginx
  45. app.kubernetes.io/instance: ingress-nginx
  46. app.kubernetes.io/version: 0.32.0
  47. app.kubernetes.io/managed-by: Helm
  48. name: ingress-nginx
  49. namespace: ingress-nginx
  50. rules:
  51. - apiGroups:
  52. - ''
  53. resources:
  54. - configmaps
  55. - endpoints
  56. - nodes
  57. - pods
  58. - secrets
  59. verbs:
  60. - list
  61. - watch
  62. - apiGroups:
  63. - ''
  64. resources:
  65. - nodes
  66. verbs:
  67. - get
  68. - apiGroups:
  69. - ''
  70. resources:
  71. - services
  72. verbs:
  73. - get
  74. - list
  75. - update
  76. - watch
  77. - apiGroups:
  78. - extensions
  79. - networking.k8s.io # k8s 1.14+
  80. resources:
  81. - ingresses
  82. verbs:
  83. - get
  84. - list
  85. - watch
  86. - apiGroups:
  87. - ''
  88. resources:
  89. - events
  90. verbs:
  91. - create
  92. - patch
  93. - apiGroups:
  94. - extensions
  95. - networking.k8s.io # k8s 1.14+
  96. resources:
  97. - ingresses/status
  98. verbs:
  99. - update
  100. - apiGroups:
  101. - networking.k8s.io # k8s 1.14+
  102. resources:
  103. - ingressclasses
  104. verbs:
  105. - get
  106. - list
  107. - watch
  108. ---
  109. # Source: ingress-nginx/templates/clusterrolebinding.yaml
  110. apiVersion: rbac.authorization.k8s.io/v1
  111. kind: ClusterRoleBinding
  112. metadata:
  113. labels:
  114. helm.sh/chart: ingress-nginx-2.0.3
  115. app.kubernetes.io/name: ingress-nginx
  116. app.kubernetes.io/instance: ingress-nginx
  117. app.kubernetes.io/version: 0.32.0
  118. app.kubernetes.io/managed-by: Helm
  119. name: ingress-nginx
  120. namespace: ingress-nginx
  121. roleRef:
  122. apiGroup: rbac.authorization.k8s.io
  123. kind: ClusterRole
  124. name: ingress-nginx
  125. subjects:
  126. - kind: ServiceAccount
  127. name: ingress-nginx
  128. namespace: ingress-nginx
  129. ---
  130. # Source: ingress-nginx/templates/controller-role.yaml
  131. apiVersion: rbac.authorization.k8s.io/v1
  132. kind: Role
  133. metadata:
  134. labels:
  135. helm.sh/chart: ingress-nginx-2.0.3
  136. app.kubernetes.io/name: ingress-nginx
  137. app.kubernetes.io/instance: ingress-nginx
  138. app.kubernetes.io/version: 0.32.0
  139. app.kubernetes.io/managed-by: Helm
  140. app.kubernetes.io/component: controller
  141. name: ingress-nginx
  142. namespace: ingress-nginx
  143. rules:
  144. - apiGroups:
  145. - ''
  146. resources:
  147. - namespaces
  148. verbs:
  149. - get
  150. - apiGroups:
  151. - ''
  152. resources:
  153. - configmaps
  154. - pods
  155. - secrets
  156. - endpoints
  157. verbs:
  158. - get
  159. - list
  160. - watch
  161. - apiGroups:
  162. - ''
  163. resources:
  164. - services
  165. verbs:
  166. - get
  167. - list
  168. - update
  169. - watch
  170. - apiGroups:
  171. - extensions
  172. - networking.k8s.io # k8s 1.14+
  173. resources:
  174. - ingresses
  175. verbs:
  176. - get
  177. - list
  178. - watch
  179. - apiGroups:
  180. - extensions
  181. - networking.k8s.io # k8s 1.14+
  182. resources:
  183. - ingresses/status
  184. verbs:
  185. - update
  186. - apiGroups:
  187. - networking.k8s.io # k8s 1.14+
  188. resources:
  189. - ingressclasses
  190. verbs:
  191. - get
  192. - list
  193. - watch
  194. - apiGroups:
  195. - ''
  196. resources:
  197. - configmaps
  198. resourceNames:
  199. - ingress-controller-leader-nginx
  200. verbs:
  201. - get
  202. - update
  203. - apiGroups:
  204. - ''
  205. resources:
  206. - configmaps
  207. verbs:
  208. - create
  209. - apiGroups:
  210. - ''
  211. resources:
  212. - endpoints
  213. verbs:
  214. - create
  215. - get
  216. - update
  217. - apiGroups:
  218. - ''
  219. resources:
  220. - events
  221. verbs:
  222. - create
  223. - patch
  224. ---
  225. # Source: ingress-nginx/templates/controller-rolebinding.yaml
  226. apiVersion: rbac.authorization.k8s.io/v1
  227. kind: RoleBinding
  228. metadata:
  229. labels:
  230. helm.sh/chart: ingress-nginx-2.0.3
  231. app.kubernetes.io/name: ingress-nginx
  232. app.kubernetes.io/instance: ingress-nginx
  233. app.kubernetes.io/version: 0.32.0
  234. app.kubernetes.io/managed-by: Helm
  235. app.kubernetes.io/component: controller
  236. name: ingress-nginx
  237. namespace: ingress-nginx
  238. roleRef:
  239. apiGroup: rbac.authorization.k8s.io
  240. kind: Role
  241. name: ingress-nginx
  242. subjects:
  243. - kind: ServiceAccount
  244. name: ingress-nginx
  245. namespace: ingress-nginx
  246. ---
  247. # Source: ingress-nginx/templates/controller-service-webhook.yaml
  248. apiVersion: v1
  249. kind: Service
  250. metadata:
  251. labels:
  252. helm.sh/chart: ingress-nginx-2.0.3
  253. app.kubernetes.io/name: ingress-nginx
  254. app.kubernetes.io/instance: ingress-nginx
  255. app.kubernetes.io/version: 0.32.0
  256. app.kubernetes.io/managed-by: Helm
  257. app.kubernetes.io/component: controller
  258. name: ingress-nginx-controller-admission
  259. namespace: ingress-nginx
  260. spec:
  261. type: ClusterIP
  262. ports:
  263. - name: https-webhook
  264. port: 443
  265. targetPort: webhook
  266. selector:
  267. app.kubernetes.io/name: ingress-nginx
  268. app.kubernetes.io/instance: ingress-nginx
  269. app.kubernetes.io/component: controller
  270. ---
  271. # Source: ingress-nginx/templates/controller-service.yaml
  272. apiVersion: v1
  273. kind: Service
  274. metadata:
  275. labels:
  276. helm.sh/chart: ingress-nginx-2.0.3
  277. app.kubernetes.io/name: ingress-nginx
  278. app.kubernetes.io/instance: ingress-nginx
  279. app.kubernetes.io/version: 0.32.0
  280. app.kubernetes.io/managed-by: Helm
  281. app.kubernetes.io/component: controller
  282. name: ingress-nginx-controller
  283. namespace: ingress-nginx
  284. spec:
  285. type: NodePort
  286. ports:
  287. - name: http
  288. port: 80
  289. protocol: TCP
  290. targetPort: http
  291. - name: https
  292. port: 443
  293. protocol: TCP
  294. targetPort: https
  295. selector:
  296. app.kubernetes.io/name: ingress-nginx
  297. app.kubernetes.io/instance: ingress-nginx
  298. app.kubernetes.io/component: controller
  299. ---
  300. # Source: ingress-nginx/templates/controller-deployment.yaml
  301. apiVersion: apps/v1
  302. kind: Deployment
  303. metadata:
  304. labels:
  305. helm.sh/chart: ingress-nginx-2.0.3
  306. app.kubernetes.io/name: ingress-nginx
  307. app.kubernetes.io/instance: ingress-nginx
  308. app.kubernetes.io/version: 0.32.0
  309. app.kubernetes.io/managed-by: Helm
  310. app.kubernetes.io/component: controller
  311. name: ingress-nginx-controller
  312. namespace: ingress-nginx
  313. spec:
  314. selector:
  315. matchLabels:
  316. app.kubernetes.io/name: ingress-nginx
  317. app.kubernetes.io/instance: ingress-nginx
  318. app.kubernetes.io/component: controller
  319. revisionHistoryLimit: 10
  320. minReadySeconds: 0
  321. template:
  322. metadata:
  323. labels:
  324. app.kubernetes.io/name: ingress-nginx
  325. app.kubernetes.io/instance: ingress-nginx
  326. app.kubernetes.io/component: controller
  327. spec:
  328. dnsPolicy: ClusterFirst
  329. containers:
  330. - name: controller
  331. image: registry.cn-shanghai.aliyuncs.com/leozhanggg/ingress/nginx-ingress-controller:0.32.0
  332. imagePullPolicy: IfNotPresent
  333. lifecycle:
  334. preStop:
  335. exec:
  336. command:
  337. - /wait-shutdown
  338. args:
  339. - /nginx-ingress-controller
  340. - --election-id=ingress-controller-leader
  341. - --ingress-class=nginx
  342. - --configmap=ingress-nginx/ingress-nginx-controller
  343. - --validating-webhook=:8443
  344. - --validating-webhook-certificate=/usr/local/certificates/cert
  345. - --validating-webhook-key=/usr/local/certificates/key
  346. securityContext:
  347. capabilities:
  348. drop:
  349. - ALL
  350. add:
  351. - NET_BIND_SERVICE
  352. runAsUser: 101
  353. allowPrivilegeEscalation: true
  354. env:
  355. - name: POD_NAME
  356. valueFrom:
  357. fieldRef:
  358. fieldPath: metadata.name
  359. - name: POD_NAMESPACE
  360. valueFrom:
  361. fieldRef:
  362. fieldPath: metadata.namespace
  363. livenessProbe:
  364. httpGet:
  365. path: /healthz
  366. port: 10254
  367. scheme: HTTP
  368. initialDelaySeconds: 10
  369. periodSeconds: 10
  370. timeoutSeconds: 1
  371. successThreshold: 1
  372. failureThreshold: 3
  373. readinessProbe:
  374. httpGet:
  375. path: /healthz
  376. port: 10254
  377. scheme: HTTP
  378. initialDelaySeconds: 10
  379. periodSeconds: 10
  380. timeoutSeconds: 1
  381. successThreshold: 1
  382. failureThreshold: 3
  383. ports:
  384. - name: http
  385. containerPort: 80
  386. protocol: TCP
  387. - name: https
  388. containerPort: 443
  389. protocol: TCP
  390. - name: webhook
  391. containerPort: 8443
  392. protocol: TCP
  393. volumeMounts:
  394. - name: webhook-cert
  395. mountPath: /usr/local/certificates/
  396. readOnly: true
  397. resources:
  398. requests:
  399. cpu: 100m
  400. memory: 90Mi
  401. serviceAccountName: ingress-nginx
  402. terminationGracePeriodSeconds: 300
  403. volumes:
  404. - name: webhook-cert
  405. secret:
  406. secretName: ingress-nginx-admission
  407. ---
  408. # Source: ingress-nginx/templates/admission-webhooks/validating-webhook.yaml
  409. apiVersion: admissionregistration.k8s.io/v1beta1
  410. kind: ValidatingWebhookConfiguration
  411. metadata:
  412. labels:
  413. helm.sh/chart: ingress-nginx-2.0.3
  414. app.kubernetes.io/name: ingress-nginx
  415. app.kubernetes.io/instance: ingress-nginx
  416. app.kubernetes.io/version: 0.32.0
  417. app.kubernetes.io/managed-by: Helm
  418. app.kubernetes.io/component: admission-webhook
  419. name: ingress-nginx-admission
  420. namespace: ingress-nginx
  421. webhooks:
  422. - name: validate.nginx.ingress.kubernetes.io
  423. rules:
  424. - apiGroups:
  425. - extensions
  426. - networking.k8s.io
  427. apiVersions:
  428. - v1beta1
  429. operations:
  430. - CREATE
  431. - UPDATE
  432. resources:
  433. - ingresses
  434. failurePolicy: Fail
  435. clientConfig:
  436. service:
  437. namespace: ingress-nginx
  438. name: ingress-nginx-controller-admission
  439. path: /extensions/v1beta1/ingresses
  440. ---
  441. # Source: ingress-nginx/templates/admission-webhooks/job-patch/clusterrole.yaml
  442. apiVersion: rbac.authorization.k8s.io/v1
  443. kind: ClusterRole
  444. metadata:
  445. name: ingress-nginx-admission
  446. annotations:
  447. helm.sh/hook: pre-install,pre-upgrade,post-install,post-upgrade
  448. helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
  449. labels:
  450. helm.sh/chart: ingress-nginx-2.0.3
  451. app.kubernetes.io/name: ingress-nginx
  452. app.kubernetes.io/instance: ingress-nginx
  453. app.kubernetes.io/version: 0.32.0
  454. app.kubernetes.io/managed-by: Helm
  455. app.kubernetes.io/component: admission-webhook
  456. namespace: ingress-nginx
  457. rules:
  458. - apiGroups:
  459. - admissionregistration.k8s.io
  460. resources:
  461. - validatingwebhookconfigurations
  462. verbs:
  463. - get
  464. - update
  465. ---
  466. # Source: ingress-nginx/templates/admission-webhooks/job-patch/clusterrolebinding.yaml
  467. apiVersion: rbac.authorization.k8s.io/v1
  468. kind: ClusterRoleBinding
  469. metadata:
  470. name: ingress-nginx-admission
  471. annotations:
  472. helm.sh/hook: pre-install,pre-upgrade,post-install,post-upgrade
  473. helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
  474. labels:
  475. helm.sh/chart: ingress-nginx-2.0.3
  476. app.kubernetes.io/name: ingress-nginx
  477. app.kubernetes.io/instance: ingress-nginx
  478. app.kubernetes.io/version: 0.32.0
  479. app.kubernetes.io/managed-by: Helm
  480. app.kubernetes.io/component: admission-webhook
  481. namespace: ingress-nginx
  482. roleRef:
  483. apiGroup: rbac.authorization.k8s.io
  484. kind: ClusterRole
  485. name: ingress-nginx-admission
  486. subjects:
  487. - kind: ServiceAccount
  488. name: ingress-nginx-admission
  489. namespace: ingress-nginx
  490. ---
  491. # Source: ingress-nginx/templates/admission-webhooks/job-patch/job-createSecret.yaml
  492. apiVersion: batch/v1
  493. kind: Job
  494. metadata:
  495. name: ingress-nginx-admission-create
  496. annotations:
  497. helm.sh/hook: pre-install,pre-upgrade
  498. helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
  499. labels:
  500. helm.sh/chart: ingress-nginx-2.0.3
  501. app.kubernetes.io/name: ingress-nginx
  502. app.kubernetes.io/instance: ingress-nginx
  503. app.kubernetes.io/version: 0.32.0
  504. app.kubernetes.io/managed-by: Helm
  505. app.kubernetes.io/component: admission-webhook
  506. namespace: ingress-nginx
  507. spec:
  508. template:
  509. metadata:
  510. name: ingress-nginx-admission-create
  511. labels:
  512. helm.sh/chart: ingress-nginx-2.0.3
  513. app.kubernetes.io/name: ingress-nginx
  514. app.kubernetes.io/instance: ingress-nginx
  515. app.kubernetes.io/version: 0.32.0
  516. app.kubernetes.io/managed-by: Helm
  517. app.kubernetes.io/component: admission-webhook
  518. spec:
  519. containers:
  520. - name: create
  521. image: registry.cn-shanghai.aliyuncs.com/leozhanggg/ingress/kube-webhook-certgen:v1.2.0
  522. imagePullPolicy: IfNotPresent
  523. args:
  524. - create
  525. - --host=ingress-nginx-controller-admission,ingress-nginx-controller-admission.ingress-nginx.svc
  526. - --namespace=ingress-nginx
  527. - --secret-name=ingress-nginx-admission
  528. restartPolicy: OnFailure
  529. serviceAccountName: ingress-nginx-admission
  530. securityContext:
  531. runAsNonRoot: true
  532. runAsUser: 2000
  533. ---
  534. # Source: ingress-nginx/templates/admission-webhooks/job-patch/job-patchWebhook.yaml
  535. apiVersion: batch/v1
  536. kind: Job
  537. metadata:
  538. name: ingress-nginx-admission-patch
  539. annotations:
  540. helm.sh/hook: post-install,post-upgrade
  541. helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
  542. labels:
  543. helm.sh/chart: ingress-nginx-2.0.3
  544. app.kubernetes.io/name: ingress-nginx
  545. app.kubernetes.io/instance: ingress-nginx
  546. app.kubernetes.io/version: 0.32.0
  547. app.kubernetes.io/managed-by: Helm
  548. app.kubernetes.io/component: admission-webhook
  549. namespace: ingress-nginx
  550. spec:
  551. template:
  552. metadata:
  553. name: ingress-nginx-admission-patch
  554. labels:
  555. helm.sh/chart: ingress-nginx-2.0.3
  556. app.kubernetes.io/name: ingress-nginx
  557. app.kubernetes.io/instance: ingress-nginx
  558. app.kubernetes.io/version: 0.32.0
  559. app.kubernetes.io/managed-by: Helm
  560. app.kubernetes.io/component: admission-webhook
  561. spec:
  562. containers:
  563. - name: patch
  564. image: registry.cn-shanghai.aliyuncs.com/leozhanggg/ingress/kube-webhook-certgen:v1.2.0
  565. imagePullPolicy:
  566. args:
  567. - patch
  568. - --webhook-name=ingress-nginx-admission
  569. - --namespace=ingress-nginx
  570. - --patch-mutating=false
  571. - --secret-name=ingress-nginx-admission
  572. - --patch-failure-policy=Fail
  573. restartPolicy: OnFailure
  574. serviceAccountName: ingress-nginx-admission
  575. securityContext:
  576. runAsNonRoot: true
  577. runAsUser: 2000
  578. ---
  579. # Source: ingress-nginx/templates/admission-webhooks/job-patch/role.yaml
  580. apiVersion: rbac.authorization.k8s.io/v1
  581. kind: Role
  582. metadata:
  583. name: ingress-nginx-admission
  584. annotations:
  585. helm.sh/hook: pre-install,pre-upgrade,post-install,post-upgrade
  586. helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
  587. labels:
  588. helm.sh/chart: ingress-nginx-2.0.3
  589. app.kubernetes.io/name: ingress-nginx
  590. app.kubernetes.io/instance: ingress-nginx
  591. app.kubernetes.io/version: 0.32.0
  592. app.kubernetes.io/managed-by: Helm
  593. app.kubernetes.io/component: admission-webhook
  594. namespace: ingress-nginx
  595. rules:
  596. - apiGroups:
  597. - ''
  598. resources:
  599. - secrets
  600. verbs:
  601. - get
  602. - create
  603. ---
  604. # Source: ingress-nginx/templates/admission-webhooks/job-patch/rolebinding.yaml
  605. apiVersion: rbac.authorization.k8s.io/v1
  606. kind: RoleBinding
  607. metadata:
  608. name: ingress-nginx-admission
  609. annotations:
  610. helm.sh/hook: pre-install,pre-upgrade,post-install,post-upgrade
  611. helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
  612. labels:
  613. helm.sh/chart: ingress-nginx-2.0.3
  614. app.kubernetes.io/name: ingress-nginx
  615. app.kubernetes.io/instance: ingress-nginx
  616. app.kubernetes.io/version: 0.32.0
  617. app.kubernetes.io/managed-by: Helm
  618. app.kubernetes.io/component: admission-webhook
  619. namespace: ingress-nginx
  620. roleRef:
  621. apiGroup: rbac.authorization.k8s.io
  622. kind: Role
  623. name: ingress-nginx-admission
  624. subjects:
  625. - kind: ServiceAccount
  626. name: ingress-nginx-admission
  627. namespace: ingress-nginx
  628. ---
  629. # Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
  630. apiVersion: v1
  631. kind: ServiceAccount
  632. metadata:
  633. name: ingress-nginx-admission
  634. annotations:
  635. helm.sh/hook: pre-install,pre-upgrade,post-install,post-upgrade
  636. helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
  637. labels:
  638. helm.sh/chart: ingress-nginx-2.0.3
  639. app.kubernetes.io/name: ingress-nginx
  640. app.kubernetes.io/instance: ingress-nginx
  641. app.kubernetes.io/version: 0.32.0
  642. app.kubernetes.io/managed-by: Helm
  643. app.kubernetes.io/component: admission-webhook
  644. namespace: ingress-nginx

kube-ingress.yaml

③ 执行以上部署文件,等待部署完成,修改Service暴露类型:

  1. [root@k8s-32 ~]# kubectl get pod -n ingress-nginx
  2. NAME READY STATUS RESTARTS AGE
  3. ingress-nginx-admission-create-mw7mv 0/1 Completed 0 23h
  4. ingress-nginx-admission-patch-k2zwl 0/1 Completed 1 23h
  5. ingress-nginx-controller-df8b8bcbd-klmlc 1/1 Running 0 23h
  6. [root@k8s-32 ~]# kubectl get svc -n ingress-nginx
  7. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  8. ingress-nginx-controller NodePort 10.111.132.119 <none> 80:30467/TCP,443:30002/TCP 23h
  9. ingress-nginx-controller-admission ClusterIP 10.100.33.182 <none> 443/TCP 23h

  2)  如果你对性能比较高,功能要求不多,那我推荐使用Nginx-ingress。由于Nginx-ingress消除了Lua代码而保证了较高的速度(与官方控制器相比),而在高并发下Nginx-ingress性能也是优于Haproxy-ingress的。

    ① 安装部署参考:https://docs.nginx.com/nginx-ingress-controller/installation/installation-with-manifests/

    ② 当然你也可以直接复制以下修改好的文件:

  1. # Source: kubernetes-ingress/deployments/common/ns-and-sa.yaml
  2. apiVersion: v1
  3. kind: Namespace
  4. metadata:
  5. name: nginx-ingress
  6. ---
  7. apiVersion: v1
  8. kind: ServiceAccount
  9. metadata:
  10. name: nginx-ingress
  11. namespace: nginx-ingress
  12. ---
  13. # Source: kubernetes-ingress/deployments/rbac/rbac.yaml
  14. kind: ClusterRole
  15. apiVersion: rbac.authorization.k8s.io/v1beta1
  16. metadata:
  17. name: nginx-ingress
  18. rules:
  19. - apiGroups:
  20. - ""
  21. resources:
  22. - services
  23. - endpoints
  24. verbs:
  25. - get
  26. - list
  27. - watch
  28. - apiGroups:
  29. - ""
  30. resources:
  31. - secrets
  32. verbs:
  33. - get
  34. - list
  35. - watch
  36. - apiGroups:
  37. - ""
  38. resources:
  39. - configmaps
  40. verbs:
  41. - get
  42. - list
  43. - watch
  44. - update
  45. - create
  46. - apiGroups:
  47. - ""
  48. resources:
  49. - pods
  50. verbs:
  51. - list
  52. - watch
  53. - apiGroups:
  54. - ""
  55. resources:
  56. - events
  57. verbs:
  58. - create
  59. - patch
  60. - apiGroups:
  61. - extensions
  62. resources:
  63. - ingresses
  64. verbs:
  65. - list
  66. - watch
  67. - get
  68. - apiGroups:
  69. - "extensions"
  70. resources:
  71. - ingresses/status
  72. verbs:
  73. - update
  74. - apiGroups:
  75. - k8s.nginx.org
  76. resources:
  77. - virtualservers
  78. - virtualserverroutes
  79. - globalconfigurations
  80. - transportservers
  81. verbs:
  82. - list
  83. - watch
  84. - get
  85. ---
  86. kind: ClusterRoleBinding
  87. apiVersion: rbac.authorization.k8s.io/v1beta1
  88. metadata:
  89. name: nginx-ingress
  90. subjects:
  91. - kind: ServiceAccount
  92. name: nginx-ingress
  93. namespace: nginx-ingress
  94. roleRef:
  95. kind: ClusterRole
  96. name: nginx-ingress
  97. apiGroup: rbac.authorization.k8s.io
  98. ---
  99. # Source: kubernetes-ingress/deployments/common/default-server-secret.yaml
  100. apiVersion: v1
  101. kind: Secret
  102. metadata:
  103. name: default-server-secret
  104. namespace: nginx-ingress
  105. type: Opaque
  106. data:
  107. tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN2akNDQWFZQ0NRREFPRjl0THNhWFhEQU5CZ2txaGtpRzl3MEJBUXNGQURBaE1SOHdIUVlEVlFRRERCWk8KUjBsT1dFbHVaM0psYzNORGIyNTBjbTlzYkdWeU1CNFhEVEU0TURreE1qRTRNRE16T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WDJ1VnRYejN5QTZnbXo5aCsKcDNlK2JMRUxwb3B0WFhNdUFRR0xhUkcrYlNNcjR5dERYbE5ZSndUeThXczNKY3dlSTdqZVp2b0ZpbmNvVlVIMwphdmxoTUVCRGYxSjltSDB5cDBwWUNaS2ROdHNvZEZtQktzVEtQMjJhTmtsVVhCS3gyZzR6cFE9PQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
  109. ---
  110. # Source: kubernetes-ingress/deployments/common/nginx-config.yaml
  111. kind: ConfigMap
  112. apiVersion: v1
  113. metadata:
  114. name: nginx-config
  115. namespace: nginx-ingress
  116. data:
  117. external-status-address: "127.0.0.1"
  118. ---
  119. # Source: kubernetes-ingress/deployments/common/vs-definition.yaml
  120. apiVersion: apiextensions.k8s.io/v1beta1
  121. kind: CustomResourceDefinition
  122. metadata:
  123. name: virtualservers.k8s.nginx.org
  124. spec:
  125. group: k8s.nginx.org
  126. versions:
  127. - name: v1
  128. served: true
  129. storage: true
  130. scope: Namespaced
  131. names:
  132. kind: VirtualServer
  133. plural: virtualservers
  134. singular: virtualserver
  135. shortNames:
  136. - vs
  137. preserveUnknownFields: false
  138. validation:
  139. openAPIV3Schema:
  140. description: VirtualServer defines the VirtualServer resource.
  141. type: object
  142. properties:
  143. apiVersion:
  144. description: 'APIVersion defines the versioned schema of this representation
  145. of an object. Servers should convert recognized schemas to the latest
  146. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  147. type: string
  148. kind:
  149. description: 'Kind is a string value representing the REST resource this
  150. object represents. Servers may infer this from the endpoint the client
  151. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  152. type: string
  153. metadata:
  154. type: object
  155. spec:
  156. description: VirtualServerSpec is the spec of the VirtualServer resource.
  157. type: object
  158. properties:
  159. host:
  160. type: string
  161. routes:
  162. type: array
  163. items:
  164. description: Route defines a route.
  165. type: object
  166. properties:
  167. action:
  168. description: Action defines an action.
  169. type: object
  170. properties:
  171. pass:
  172. type: string
  173. redirect:
  174. description: ActionRedirect defines a redirect in an Action.
  175. type: object
  176. properties:
  177. code:
  178. type: integer
  179. url:
  180. type: string
  181. return:
  182. description: ActionReturn defines a return in an Action.
  183. type: object
  184. properties:
  185. body:
  186. type: string
  187. code:
  188. type: integer
  189. type:
  190. type: string
  191. errorPages:
  192. type: array
  193. items:
  194. description: ErrorPage defines an ErrorPage in a Route.
  195. type: object
  196. properties:
  197. codes:
  198. type: array
  199. items:
  200. type: integer
  201. redirect:
  202. description: ErrorPageRedirect defines a redirect for an
  203. ErrorPage.
  204. type: object
  205. properties:
  206. code:
  207. type: integer
  208. url:
  209. type: string
  210. return:
  211. description: ErrorPageReturn defines a return for an ErrorPage.
  212. type: object
  213. properties:
  214. body:
  215. type: string
  216. code:
  217. type: integer
  218. headers:
  219. type: array
  220. items:
  221. description: Header defines an HTTP Header.
  222. type: object
  223. properties:
  224. name:
  225. type: string
  226. value:
  227. type: string
  228. type:
  229. type: string
  230. matches:
  231. type: array
  232. items:
  233. description: Match defines a match.
  234. type: object
  235. properties:
  236. action:
  237. description: Action defines an action.
  238. type: object
  239. properties:
  240. pass:
  241. type: string
  242. redirect:
  243. description: ActionRedirect defines a redirect in an
  244. Action.
  245. type: object
  246. properties:
  247. code:
  248. type: integer
  249. url:
  250. type: string
  251. return:
  252. description: ActionReturn defines a return in an Action.
  253. type: object
  254. properties:
  255. body:
  256. type: string
  257. code:
  258. type: integer
  259. type:
  260. type: string
  261. conditions:
  262. type: array
  263. items:
  264. description: Condition defines a condition in a MatchRule.
  265. type: object
  266. properties:
  267. argument:
  268. type: string
  269. cookie:
  270. type: string
  271. header:
  272. type: string
  273. value:
  274. type: string
  275. variable:
  276. type: string
  277. splits:
  278. type: array
  279. items:
  280. description: Split defines a split.
  281. type: object
  282. properties:
  283. action:
  284. description: Action defines an action.
  285. type: object
  286. properties:
  287. pass:
  288. type: string
  289. redirect:
  290. description: ActionRedirect defines a redirect
  291. in an Action.
  292. type: object
  293. properties:
  294. code:
  295. type: integer
  296. url:
  297. type: string
  298. return:
  299. description: ActionReturn defines a return in
  300. an Action.
  301. type: object
  302. properties:
  303. body:
  304. type: string
  305. code:
  306. type: integer
  307. type:
  308. type: string
  309. weight:
  310. type: integer
  311. path:
  312. type: string
  313. route:
  314. type: string
  315. splits:
  316. type: array
  317. items:
  318. description: Split defines a split.
  319. type: object
  320. properties:
  321. action:
  322. description: Action defines an action.
  323. type: object
  324. properties:
  325. pass:
  326. type: string
  327. redirect:
  328. description: ActionRedirect defines a redirect in an
  329. Action.
  330. type: object
  331. properties:
  332. code:
  333. type: integer
  334. url:
  335. type: string
  336. return:
  337. description: ActionReturn defines a return in an Action.
  338. type: object
  339. properties:
  340. body:
  341. type: string
  342. code:
  343. type: integer
  344. type:
  345. type: string
  346. weight:
  347. type: integer
  348. tls:
  349. description: TLS defines TLS configuration for a VirtualServer.
  350. type: object
  351. properties:
  352. redirect:
  353. description: TLSRedirect defines a redirect for a TLS.
  354. type: object
  355. properties:
  356. basedOn:
  357. type: string
  358. code:
  359. type: integer
  360. enable:
  361. type: boolean
  362. secret:
  363. type: string
  364. upstreams:
  365. type: array
  366. items:
  367. description: Upstream defines an upstream.
  368. type: object
  369. properties:
  370. buffer-size:
  371. type: string
  372. buffering:
  373. type: boolean
  374. buffers:
  375. description: UpstreamBuffers defines Buffer Configuration for
  376. an Upstream.
  377. type: object
  378. properties:
  379. number:
  380. type: integer
  381. size:
  382. type: string
  383. client-max-body-size:
  384. type: string
  385. connect-timeout:
  386. type: string
  387. fail-timeout:
  388. type: string
  389. healthCheck:
  390. description: HealthCheck defines the parameters for active Upstream
  391. HealthChecks.
  392. type: object
  393. properties:
  394. connect-timeout:
  395. type: string
  396. enable:
  397. type: boolean
  398. fails:
  399. type: integer
  400. headers:
  401. type: array
  402. items:
  403. description: Header defines an HTTP Header.
  404. type: object
  405. properties:
  406. name:
  407. type: string
  408. value:
  409. type: string
  410. interval:
  411. type: string
  412. jitter:
  413. type: string
  414. passes:
  415. type: integer
  416. path:
  417. type: string
  418. port:
  419. type: integer
  420. read-timeout:
  421. type: string
  422. send-timeout:
  423. type: string
  424. statusMatch:
  425. type: string
  426. tls:
  427. description: UpstreamTLS defines a TLS configuration for an
  428. Upstream.
  429. type: object
  430. properties:
  431. enable:
  432. type: boolean
  433. keepalive:
  434. type: integer
  435. lb-method:
  436. type: string
  437. max-conns:
  438. type: integer
  439. max-fails:
  440. type: integer
  441. name:
  442. type: string
  443. next-upstream:
  444. type: string
  445. next-upstream-timeout:
  446. type: string
  447. next-upstream-tries:
  448. type: integer
  449. port:
  450. type: integer
  451. queue:
  452. description: UpstreamQueue defines Queue Configuration for an
  453. Upstream.
  454. type: object
  455. properties:
  456. size:
  457. type: integer
  458. timeout:
  459. type: string
  460. read-timeout:
  461. type: string
  462. send-timeout:
  463. type: string
  464. service:
  465. type: string
  466. sessionCookie:
  467. description: SessionCookie defines the parameters for session
  468. persistence.
  469. type: object
  470. properties:
  471. domain:
  472. type: string
  473. enable:
  474. type: boolean
  475. expires:
  476. type: string
  477. httpOnly:
  478. type: boolean
  479. name:
  480. type: string
  481. path:
  482. type: string
  483. secure:
  484. type: boolean
  485. slow-start:
  486. type: string
  487. subselector:
  488. type: object
  489. additionalProperties:
  490. type: string
  491. tls:
  492. description: UpstreamTLS defines a TLS configuration for an Upstream.
  493. type: object
  494. properties:
  495. enable:
  496. type: boolean
  497. ---
  498. # Source: kubernetes-ingress/deployments/common/vsr-definition.yaml
  499. apiVersion: apiextensions.k8s.io/v1beta1
  500. kind: CustomResourceDefinition
  501. metadata:
  502. name: virtualserverroutes.k8s.nginx.org
  503. spec:
  504. group: k8s.nginx.org
  505. versions:
  506. - name: v1
  507. served: true
  508. storage: true
  509. scope: Namespaced
  510. names:
  511. kind: VirtualServerRoute
  512. plural: virtualserverroutes
  513. singular: virtualserverroute
  514. shortNames:
  515. - vsr
  516. preserveUnknownFields: false
  517. validation:
  518. openAPIV3Schema:
  519. type: object
  520. properties:
  521. apiVersion:
  522. description: 'APIVersion defines the versioned schema of this representation
  523. of an object. Servers should convert recognized schemas to the latest
  524. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  525. type: string
  526. kind:
  527. description: 'Kind is a string value representing the REST resource this
  528. object represents. Servers may infer this from the endpoint the client
  529. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  530. type: string
  531. metadata:
  532. type: object
  533. spec:
  534. type: object
  535. properties:
  536. host:
  537. type: string
  538. subroutes:
  539. type: array
  540. items:
  541. description: Route defines a route.
  542. type: object
  543. properties:
  544. action:
  545. description: Action defines an action.
  546. type: object
  547. properties:
  548. pass:
  549. type: string
  550. redirect:
  551. description: ActionRedirect defines a redirect in an Action.
  552. type: object
  553. properties:
  554. code:
  555. type: integer
  556. url:
  557. type: string
  558. return:
  559. description: ActionReturn defines a return in an Action.
  560. type: object
  561. properties:
  562. body:
  563. type: string
  564. code:
  565. type: integer
  566. type:
  567. type: string
  568. errorPages:
  569. type: array
  570. items:
  571. description: ErrorPage defines an ErrorPage in a Route.
  572. type: object
  573. properties:
  574. codes:
  575. type: array
  576. items:
  577. type: integer
  578. redirect:
  579. description: ErrorPageRedirect defines a redirect for an
  580. ErrorPage.
  581. type: object
  582. properties:
  583. code:
  584. type: integer
  585. url:
  586. type: string
  587. return:
  588. description: ErrorPageReturn defines a return for an ErrorPage.
  589. type: object
  590. properties:
  591. body:
  592. type: string
  593. code:
  594. type: integer
  595. headers:
  596. type: array
  597. items:
  598. description: Header defines an HTTP Header.
  599. type: object
  600. properties:
  601. name:
  602. type: string
  603. value:
  604. type: string
  605. type:
  606. type: string
  607. matches:
  608. type: array
  609. items:
  610. description: Match defines a match.
  611. type: object
  612. properties:
  613. action:
  614. description: Action defines an action.
  615. type: object
  616. properties:
  617. pass:
  618. type: string
  619. redirect:
  620. description: ActionRedirect defines a redirect in an
  621. Action.
  622. type: object
  623. properties:
  624. code:
  625. type: integer
  626. url:
  627. type: string
  628. return:
  629. description: ActionReturn defines a return in an Action.
  630. type: object
  631. properties:
  632. body:
  633. type: string
  634. code:
  635. type: integer
  636. type:
  637. type: string
  638. conditions:
  639. type: array
  640. items:
  641. description: Condition defines a condition in a MatchRule.
  642. type: object
  643. properties:
  644. argument:
  645. type: string
  646. cookie:
  647. type: string
  648. header:
  649. type: string
  650. value:
  651. type: string
  652. variable:
  653. type: string
  654. splits:
  655. type: array
  656. items:
  657. description: Split defines a split.
  658. type: object
  659. properties:
  660. action:
  661. description: Action defines an action.
  662. type: object
  663. properties:
  664. pass:
  665. type: string
  666. redirect:
  667. description: ActionRedirect defines a redirect
  668. in an Action.
  669. type: object
  670. properties:
  671. code:
  672. type: integer
  673. url:
  674. type: string
  675. return:
  676. description: ActionReturn defines a return in
  677. an Action.
  678. type: object
  679. properties:
  680. body:
  681. type: string
  682. code:
  683. type: integer
  684. type:
  685. type: string
  686. weight:
  687. type: integer
  688. path:
  689. type: string
  690. route:
  691. type: string
  692. splits:
  693. type: array
  694. items:
  695. description: Split defines a split.
  696. type: object
  697. properties:
  698. action:
  699. description: Action defines an action.
  700. type: object
  701. properties:
  702. pass:
  703. type: string
  704. redirect:
  705. description: ActionRedirect defines a redirect in an
  706. Action.
  707. type: object
  708. properties:
  709. code:
  710. type: integer
  711. url:
  712. type: string
  713. return:
  714. description: ActionReturn defines a return in an Action.
  715. type: object
  716. properties:
  717. body:
  718. type: string
  719. code:
  720. type: integer
  721. type:
  722. type: string
  723. weight:
  724. type: integer
  725. upstreams:
  726. type: array
  727. items:
  728. description: Upstream defines an upstream.
  729. type: object
  730. properties:
  731. buffer-size:
  732. type: string
  733. buffering:
  734. type: boolean
  735. buffers:
  736. description: UpstreamBuffers defines Buffer Configuration for
  737. an Upstream.
  738. type: object
  739. properties:
  740. number:
  741. type: integer
  742. size:
  743. type: string
  744. client-max-body-size:
  745. type: string
  746. connect-timeout:
  747. type: string
  748. fail-timeout:
  749. type: string
  750. healthCheck:
  751. description: HealthCheck defines the parameters for active Upstream
  752. HealthChecks.
  753. type: object
  754. properties:
  755. connect-timeout:
  756. type: string
  757. enable:
  758. type: boolean
  759. fails:
  760. type: integer
  761. headers:
  762. type: array
  763. items:
  764. description: Header defines an HTTP Header.
  765. type: object
  766. properties:
  767. name:
  768. type: string
  769. value:
  770. type: string
  771. interval:
  772. type: string
  773. jitter:
  774. type: string
  775. passes:
  776. type: integer
  777. path:
  778. type: string
  779. port:
  780. type: integer
  781. read-timeout:
  782. type: string
  783. send-timeout:
  784. type: string
  785. statusMatch:
  786. type: string
  787. tls:
  788. description: UpstreamTLS defines a TLS configuration for an
  789. Upstream.
  790. type: object
  791. properties:
  792. enable:
  793. type: boolean
  794. keepalive:
  795. type: integer
  796. lb-method:
  797. type: string
  798. max-conns:
  799. type: integer
  800. max-fails:
  801. type: integer
  802. name:
  803. type: string
  804. next-upstream:
  805. type: string
  806. next-upstream-timeout:
  807. type: string
  808. next-upstream-tries:
  809. type: integer
  810. port:
  811. type: integer
  812. queue:
  813. description: UpstreamQueue defines Queue Configuration for an
  814. Upstream.
  815. type: object
  816. properties:
  817. size:
  818. type: integer
  819. timeout:
  820. type: string
  821. read-timeout:
  822. type: string
  823. send-timeout:
  824. type: string
  825. service:
  826. type: string
  827. sessionCookie:
  828. description: SessionCookie defines the parameters for session
  829. persistence.
  830. type: object
  831. properties:
  832. domain:
  833. type: string
  834. enable:
  835. type: boolean
  836. expires:
  837. type: string
  838. httpOnly:
  839. type: boolean
  840. name:
  841. type: string
  842. path:
  843. type: string
  844. secure:
  845. type: boolean
  846. slow-start:
  847. type: string
  848. subselector:
  849. type: object
  850. additionalProperties:
  851. type: string
  852. tls:
  853. description: UpstreamTLS defines a TLS configuration for an Upstream.
  854. type: object
  855. properties:
  856. enable:
  857. type: boolean
  858. ---
  859. # Source: kubernetes-ingress/deployments/common/ts-definition.yaml
  860. apiVersion: apiextensions.k8s.io/v1beta1
  861. kind: CustomResourceDefinition
  862. metadata:
  863. name: transportservers.k8s.nginx.org
  864. spec:
  865. group: k8s.nginx.org
  866. versions:
  867. - name: v1alpha1
  868. served: true
  869. storage: true
  870. scope: Namespaced
  871. names:
  872. plural: transportservers
  873. singular: transportserver
  874. kind: TransportServer
  875. shortNames:
  876. - ts
  877. preserveUnknownFields: false
  878. validation:
  879. openAPIV3Schema:
  880. description: TransportServer defines the TransportServer resource.
  881. type: object
  882. properties:
  883. apiVersion:
  884. description: 'APIVersion defines the versioned schema of this representation
  885. of an object. Servers should convert recognized schemas to the latest
  886. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  887. type: string
  888. kind:
  889. description: 'Kind is a string value representing the REST resource this
  890. object represents. Servers may infer this from the endpoint the client
  891. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  892. type: string
  893. metadata:
  894. type: object
  895. spec:
  896. description: TransportServerSpec is the spec of the TransportServer resource.
  897. type: object
  898. properties:
  899. action:
  900. description: Action defines an action.
  901. type: object
  902. properties:
  903. pass:
  904. type: string
  905. host:
  906. type: string
  907. listener:
  908. description: TransportServerListener defines a listener for a TransportServer.
  909. type: object
  910. properties:
  911. name:
  912. type: string
  913. protocol:
  914. type: string
  915. upstreamParameters:
  916. description: UpstreamParameters defines parameters for an upstream.
  917. type: object
  918. properties:
  919. udpRequests:
  920. type: integer
  921. udpResponses:
  922. type: integer
  923. upstreams:
  924. type: array
  925. items:
  926. description: Upstream defines an upstream.
  927. type: object
  928. properties:
  929. name:
  930. type: string
  931. port:
  932. type: integer
  933. service:
  934. type: string
  935. ---
  936. # Source: kubernetes-ingress/deployments/common/gc-definition.yaml
  937. apiVersion: apiextensions.k8s.io/v1beta1
  938. kind: CustomResourceDefinition
  939. metadata:
  940. name: globalconfigurations.k8s.nginx.org
  941. spec:
  942. group: k8s.nginx.org
  943. versions:
  944. - name: v1alpha1
  945. served: true
  946. storage: true
  947. scope: Namespaced
  948. names:
  949. plural: globalconfigurations
  950. singular: globalconfiguration
  951. kind: GlobalConfiguration
  952. shortNames:
  953. - gc
  954. preserveUnknownFields: false
  955. validation:
  956. openAPIV3Schema:
  957. description: GlobalConfiguration defines the GlobalConfiguration resource.
  958. type: object
  959. properties:
  960. apiVersion:
  961. description: 'APIVersion defines the versioned schema of this representation
  962. of an object. Servers should convert recognized schemas to the latest
  963. internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
  964. type: string
  965. kind:
  966. description: 'Kind is a string value representing the REST resource this
  967. object represents. Servers may infer this from the endpoint the client
  968. submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
  969. type: string
  970. metadata:
  971. type: object
  972. spec:
  973. description: GlobalConfigurationSpec is the spec of the GlobalConfiguration
  974. resource.
  975. type: object
  976. properties:
  977. listeners:
  978. type: array
  979. items:
  980. description: Listener defines a listener.
  981. type: object
  982. properties:
  983. name:
  984. type: string
  985. port:
  986. type: integer
  987. protocol:
  988. type: string
  989. ---
  990. # Source: kubernetes-ingress/deployments/common/global-configuration.yaml
  991. apiVersion: k8s.nginx.org/v1alpha1
  992. kind: GlobalConfiguration
  993. metadata:
  994. name: nginx-configuration
  995. namespace: nginx-ingress
  996. ---
  997. # Source: kubernetes-ingress/deployments/daemon-set/nginx-ingress.yaml
  998. apiVersion: apps/v1
  999. kind: DaemonSet
  1000. metadata:
  1001. name: nginx-ingress
  1002. namespace: nginx-ingress
  1003. spec:
  1004. selector:
  1005. matchLabels:
  1006. app: nginx-ingress
  1007. template:
  1008. metadata:
  1009. labels:
  1010. app: nginx-ingress
  1011. #annotations:
  1012. #prometheus.io/scrape: "true"
  1013. #prometheus.io/port: "9113"
  1014. spec:
  1015. serviceAccountName: nginx-ingress
  1016. containers:
  1017. - image: nginx/nginx-ingress:1.7.1
  1018. name: nginx-ingress
  1019. ports:
  1020. - name: http
  1021. containerPort: 80
  1022. hostPort: 80
  1023. - name: https
  1024. containerPort: 443
  1025. hostPort: 443
  1026. #- name: prometheus
  1027. #containerPort: 9113
  1028. securityContext:
  1029. allowPrivilegeEscalation: true
  1030. runAsUser: 101 #nginx
  1031. capabilities:
  1032. drop:
  1033. - ALL
  1034. add:
  1035. - NET_BIND_SERVICE
  1036. env:
  1037. - name: POD_NAMESPACE
  1038. valueFrom:
  1039. fieldRef:
  1040. fieldPath: metadata.namespace
  1041. - name: POD_NAME
  1042. valueFrom:
  1043. fieldRef:
  1044. fieldPath: metadata.name
  1045. args:
  1046. - -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
  1047. - -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
  1048. #- -v=3 # Enables extensive logging. Useful for troubleshooting.
  1049. - -report-ingress-status
  1050. - -external-service=nginx-ingress
  1051. - -enable-leader-election
  1052. #- -enable-prometheus-metrics
  1053. - -global-configuration=$(POD_NAMESPACE)/nginx-configuration
  1054. ---
  1055. # Source: kubernetes-ingress/deployments/service/nodeport.yaml
  1056. apiVersion: v1
  1057. kind: Service
  1058. metadata:
  1059. name: nginx-ingress
  1060. namespace: nginx-ingress
  1061. spec:
  1062. #externalTrafficPolicy: Local
  1063. #type: LoadBalancer
  1064. type: NodePort
  1065. ports:
  1066. - port: 80
  1067. targetPort: 80
  1068. protocol: TCP
  1069. name: http
  1070. - port: 443
  1071. targetPort: 443
  1072. protocol: TCP
  1073. name: https
  1074. selector:
  1075. app: nginx-ingress
  1076. ---
  1077. # kubectl delete namespace nginx-ingress
  1078. # kubectl delete clusterrole nginx-ingress
  1079. # kubectl delete clusterrolebinding nginx-ingress

nginx-ingress.yaml

    ③ 执行以上部署文件,等待部署完成,修改nginx-config,配置负载地址:

[root@k8s147 ~]# kubectl get pod -n nginx-ingress
NAME READY STATUS RESTARTS AGE
nginx-ingress-6m4nm 1/1 Running 1 9d
nginx-ingress-d9b5r 1/1 Running 1 9d
[root@k8s147 ~]# kubectl get svc -n nginx-ingress
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-ingress NodePort 10.104.157.46 <none> 80:30080/TCP,443:30443/TCP 9d
[root@k8s147 ~]# kubectl get cm nginx-config -oyaml -n nginx-ingress
apiVersion: v1
data:
external-status-address: 10.88.88.147
kind: ConfigMap
metadata:
creationTimestamp: "2020-06-23T01:03:30Z"
name: nginx-config
namespace: nginx-ingress
resourceVersion: ""
selfLink: /api/v1/namespaces/nginx-ingress/configmaps/nginx-config
uid: b7cfa1c3-204a-4310-8859-096dcd3980ba
[root@k8s147 ~]# kubectl edit cm nginx-config -n nginx-ingress
Edit cancelled, no changes made.

更多参考 >>> ingress-nginx性能测试       HAProxy和NGINX性能进行基准测试

  3)  如果你追求功能的全面,服务网络的管理,那我推荐使用Istio。Istio开始就是与k8s结合设计的,可以说是一个非常牛逼的落地微服务架构,优点太多,缺点就是一句话 “老子学不动了!!!”。


四、不同场景配置

  1、单服务 Ingress

现有的 Kubernetes 概念允许您暴露单个 Servic,你也可以通过指定无规则的 默认后端 来对 Ingress 进行此操作。

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: test-ingress
spec:
backend:
serviceName: test-svc
servicePort: 80

  2、简单分列

一个分列配置根据请求的 HTTP URI 将流量从单个 IP 地址路由到多个服务。

foo.bar.com -> 178.91.123.132 -> / foo    service1:4200
/ bar service2:8080
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: simple-fanout-example
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: foo.bar.com
http:
paths:
- path: /foo
backend:
serviceName: service1
servicePort: 4200
- path: /bar
backend:
serviceName: service2
servicePort: 8080

3、基于名称的虚拟托管

基于名称的虚拟主机支持将 HTTP 流量路由到同一 IP 地址上的多个主机名。

foo.bar.com --|                 |-> foo.bar.com service1:80
| 178.91.123.132 |
bar.foo.com --| |-> bar.foo.com service2:80
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: name-virtual-host-ingress
spec:
rules:
- host: foo.bar.com
http:
paths:
- backend:
serviceName: service1
servicePort: 80
- host: bar.foo.com
http:
paths:
- backend:
serviceName: service2
servicePort: 80

  注意:如果您创建的 Ingress 资源没有规则中定义的任何主机(host),则可以匹配到你 Ingress 控制器 IP 地址的任何网络流量,而无需基于名称的虚拟主机。

4、TLS安全设置

你可以通过指定包含 TLS 私钥和证书的 secret 来加密 Ingress, TLS Secret 必须包含名为 tls.crt 和 tls.key 的密钥,这些密钥包含用于 TLS 的证书和私钥,例如:

apiVersion: v1
kind: Secret
metadata:
name: secret-tls
namespace: default
data:
tls.crt: base64 encoded cert
tls.key: base64 encoded key
type: kubernetes.io/tls

或者,通过openssl工具生产证书,然后通过kubectl命令创建一个secret tls资源。

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=sslexample.foo.com"
kubectl create secret tls secret-tls --key tls.key --cert tls.crt

另外,你需要确保创建的 TLS secret 来自包含 sslexample.foo.com 的公用名称(CN)的证书,也被称为全限定域名(FQDN)。

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: tls-example-ingress
spec:
tls:
- hosts:
- sslexample.foo.com
secretName: secret-tls
rules:
- host: sslexample.foo.com
http:
paths:
- path: /
backend:
serviceName: service1
servicePort: 80

  5、查看访问

我们可以通过 kubectl get 查看 ingress 资源列表

$ kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
simple-fanout-example foo.bar.com 203.0.113.123 80 59s

  我们也可以通过 kubectl describe 查看 ingress 资源详情

$ kubectl describe ingress simple-fanout-example
Name: simple-fanout-example
Namespace: default
Address: 178.91.123.132
Default backend: default-http-backend:80 (10.8.2.3:8080)
Rules:
Host Path Backends
---- ---- --------
foo.bar.com
/foo service1:4200 (10.8.0.90:4200)
/bar service2:8080 (10.8.0.91:8080)
Annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ADD 22s loadbalancer-controller default/test

  最后我们可以通过 http协议 + 负载地址 + 控制器端口 + uri 访问到服务。

curl -H 'foo.bar.com' http://203.0.113.123/foo/

五、我对Ingress性能测试

  测试工具:wrk性能测试(详解)

  由于测试环境比较混乱,配置一般,所以测试结果不一定完全准确,仅供参数。

  根据以上测试结果可以看出,kube-ingress性能存在较大的问题,虽然可以通过调节参数来实现性能优化,但是从各方面资料得知,依然与nginx存在较大差异。

  而nginx-ingress效果就比较显著,性能与原生nginx无太大差异。另外在部署方面,建议启用daemon-set模式来平滑扩大控制器的副本到各个节点,以提高ingress的性能。

作者:Leozhanggg

出处:https://www.cnblogs.com/leozhanggg/p/13189173.html

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

Kubernetes实战总结 - Ingress选型与应用的更多相关文章

  1. 新书推荐《再也不踩坑的Kubernetes实战指南》

      <再也不踩坑的Kubernetes实战指南>终于出版啦.目前可以在京东.天猫购买,京东自营和当当网预计一个星期左右上架. 本书贴合生产环境经验,解决在初次使用或者是构建集群中的痛点,帮 ...

  2. kubernetes实战(二十八):Kubernetes一键式资源管理平台Ratel安装及使用

    1. Ratel是什么? Ratel是一个Kubernetes资源平台,基于管理Kubernetes的资源开发,可以管理Kubernetes的Deployment.DaemonSet.Stateful ...

  3. 2020 最新 Kubernetes实战指南

    1.Kubernetes带来的变革   对于开发人员 由于公司业务多,开发环境.测试环境.预生产环境和生产环境都是隔离的,而且除了生产环境,为了节省成本,其他环境可能是没有日志收集的,在没有用k8s的 ...

  4. Kubernetes实战总结 - 阿里云ECS自建K8S集群

    一.概述 详情参考阿里云说明:https://help.aliyun.com/document_detail/98886.html?spm=a2c4g.11186623.6.1078.323b1c9b ...

  5. kubernetes 实战6_命令_Share Process Namespace between Containers in a Pod&Translate a Docker Compose File to Kubernetes Resources

    Share Process Namespace between Containers in a Pod how to configure process namespace sharing for a ...

  6. kubernetes对象之Ingress

    系列目录 概述 向外网暴露集群内服务,以使客户端能够访问,有以下几种方法,本文重点描述Ingress. LoadBalancer LoadBalancer一般由云服务供应商提供或者用户自定义,运行在集 ...

  7. kubernetes实战(二十六):kubeadm 安装 高可用 k8s v1.16.x dashboard 2.x

    1.基本配置 基本配置.内核升级.基本服务安装参考https://www.cnblogs.com/dukuan/p/10278637.html,或者参考<再也不踩坑的Kubernetes实战指南 ...

  8. Kubernetes 系列(三):Kubernetes使用Traefik Ingress暴露服务

    一.Kubernetes 服务暴露介绍 从 kubernetes 1.2 版本开始,kubernetes提供了 Ingress 对象来实现对外暴露服务:到目前为止 kubernetes 总共有三种暴露 ...

  9. kubernetes实战(二十七):CentOS 8 二进制 高可用 安装 k8s 1.16.x

    1. 基本说明 本文章将演示CentOS 8二进制方式安装高可用k8s 1.16.x,相对于其他版本,二进制安装方式并无太大区别.CentOS 8相对于CentOS 7操作更加方便,比如一些服务的关闭 ...

随机推荐

  1. Java实现 LeetCode 137 只出现一次的数字 II(二)

    137. 只出现一次的数字 II 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现了三次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用额外空 ...

  2. Java实现 蓝桥杯VIP 算法提高 洗牌

    算法提高 洗牌 时间限制:1.0s 内存限制:256.0MB 问题描述 小弱T在闲暇的时候会和室友打扑克,输的人就要负责洗牌.虽然小弱T不怎么会洗牌,但是他却总是输. 渐渐地小弱T发现了一个规律:只要 ...

  3. java实现第四届蓝桥杯大臣的旅费

    大臣的旅费 题目描述 很久以前,T王国空前繁荣.为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市. 为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个大 ...

  4. PAT 有理数四则运算

    本题要求编写程序,计算 2 个有理数的和.差.积.商. 输入格式: 输入在一行中按照 a1/b1 a2/b2 的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前 ...

  5. webpack从单页面到多页面

    前言 从上次更完webpack从什么都不懂到入门之后,好久没有更新过文章了,可能是因为自己懒了吧.今天看了下自己的索引量少了一半o(╥﹏╥)o,发现事态严重,赶紧更新一篇23333 也是因为最近踩了一 ...

  6. opencl(5)缓存对象

    //创建的内存对象由内核访问,将缓冲区作为参数传递给内核 1:创建缓存对象 cl_mem clCreateBuffer( cl_context context, //上下文 cl_mem_flags ...

  7. mysql基础-新版5.7.10源码安装-记录(一)

    0x01 MySQL 从 5.5 版本开始,通过 ./configure 进行编译配置方式已经被取消,取而代之的是 cmake 工具 引用一句话 cmake的重要特性之一是其独立于源码(out-of- ...

  8. Linux网卡驱动移植--Dm9000网卡驱动分析

    1. Linux网络体系结构由以下5部分组成 ① 系统调用接口: 位于Linux网络子系统的顶部,为应用程序提供访问内核网络子系统的方法,主要指socket系统调用. ② 协议无关接口: 实现一组基于 ...

  9. 使用WPF实现的 喜马拉雅FM 资源下载工具

    因为喜马拉雅pc网站上没有提供下载功能,之前有个同事问我有没有办法将资源下载到本地,当然通过浏览器F12也能找到下载地址,但挺麻烦.正好最近想学wpf,周末在家也没事,于是对着百度撸了下代码.当然只能 ...

  10. 171.Excel列表序号

    2020-03-17 Excel表列序号 A -> 1. B -> 2 Z -> 26 AA -> 27 ZY -> 701 示例: 输入: s = "LEET ...