• 云原生(三十一) | Kubernetes篇之Kubernetes平台基本预装资源


    文章目录

    Kubernetes平台基本预装资源

    一、metrics-server

    二、ingress-nginx

    三、dashboard

    四、helm应用商店


    Kubernetes平台基本预装资源

    kubernetes平台安装完成后需要安装基本资源,

    本文适配 kubernetes-v1.21.1 版本

    一、metrics-server

    GitHub - kubernetes-sigs/metrics-server: Scalable and efficient source of container resource metrics for Kubernetes built-in autoscaling pipelines.icon-default.png?t=M5H6https://github.com/kubernetes-sigs/metrics-server k8s平台基本指标监控组件

    1. apiVersion: v1
    2. kind: ServiceAccount
    3. metadata:
    4. labels:
    5. k8s-app: metrics-server
    6. name: metrics-server
    7. namespace: kube-system
    8. ---
    9. apiVersion: rbac.authorization.k8s.io/v1
    10. kind: ClusterRole
    11. metadata:
    12. labels:
    13. k8s-app: metrics-server
    14. rbac.authorization.k8s.io/aggregate-to-admin: "true"
    15. rbac.authorization.k8s.io/aggregate-to-edit: "true"
    16. rbac.authorization.k8s.io/aggregate-to-view: "true"
    17. name: system:aggregated-metrics-reader
    18. rules:
    19. - apiGroups:
    20. - metrics.k8s.io
    21. resources:
    22. - pods
    23. - nodes
    24. verbs:
    25. - get
    26. - list
    27. - watch
    28. ---
    29. apiVersion: rbac.authorization.k8s.io/v1
    30. kind: ClusterRole
    31. metadata:
    32. labels:
    33. k8s-app: metrics-server
    34. name: system:metrics-server
    35. rules:
    36. - apiGroups:
    37. - ""
    38. resources:
    39. - pods
    40. - nodes
    41. - nodes/stats
    42. - namespaces
    43. - configmaps
    44. verbs:
    45. - get
    46. - list
    47. - watch
    48. ---
    49. apiVersion: rbac.authorization.k8s.io/v1
    50. kind: RoleBinding
    51. metadata:
    52. labels:
    53. k8s-app: metrics-server
    54. name: metrics-server-auth-reader
    55. namespace: kube-system
    56. roleRef:
    57. apiGroup: rbac.authorization.k8s.io
    58. kind: Role
    59. name: extension-apiserver-authentication-reader
    60. subjects:
    61. - kind: ServiceAccount
    62. name: metrics-server
    63. namespace: kube-system
    64. ---
    65. apiVersion: rbac.authorization.k8s.io/v1
    66. kind: ClusterRoleBinding
    67. metadata:
    68. labels:
    69. k8s-app: metrics-server
    70. name: metrics-server:system:auth-delegator
    71. roleRef:
    72. apiGroup: rbac.authorization.k8s.io
    73. kind: ClusterRole
    74. name: system:auth-delegator
    75. subjects:
    76. - kind: ServiceAccount
    77. name: metrics-server
    78. namespace: kube-system
    79. ---
    80. apiVersion: rbac.authorization.k8s.io/v1
    81. kind: ClusterRoleBinding
    82. metadata:
    83. labels:
    84. k8s-app: metrics-server
    85. name: system:metrics-server
    86. roleRef:
    87. apiGroup: rbac.authorization.k8s.io
    88. kind: ClusterRole
    89. name: system:metrics-server
    90. subjects:
    91. - kind: ServiceAccount
    92. name: metrics-server
    93. namespace: kube-system
    94. ---
    95. apiVersion: v1
    96. kind: Service
    97. metadata:
    98. labels:
    99. k8s-app: metrics-server
    100. name: metrics-server
    101. namespace: kube-system
    102. spec:
    103. ports:
    104. - name: https
    105. port: 443
    106. protocol: TCP
    107. targetPort: https
    108. selector:
    109. k8s-app: metrics-server
    110. ---
    111. apiVersion: apps/v1
    112. kind: Deployment
    113. metadata:
    114. labels:
    115. k8s-app: metrics-server
    116. name: metrics-server
    117. namespace: kube-system
    118. spec:
    119. selector:
    120. matchLabels:
    121. k8s-app: metrics-server
    122. strategy:
    123. rollingUpdate:
    124. maxUnavailable: 0
    125. template:
    126. metadata:
    127. labels:
    128. k8s-app: metrics-server
    129. spec:
    130. containers:
    131. - args:
    132. - --v=6
    133. - --cert-dir=/tmp
    134. - --kubelet-insecure-tls
    135. - --secure-port=4443
    136. - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
    137. - --kubelet-use-node-status-port
    138. image: registry.cn-hangzhou.aliyuncs.com/lanson_k8s_images/metrics-server:v0.4.3
    139. imagePullPolicy: IfNotPresent
    140. livenessProbe:
    141. failureThreshold: 3
    142. httpGet:
    143. path: /livez
    144. port: https
    145. scheme: HTTPS
    146. periodSeconds: 10
    147. name: metrics-server
    148. ports:
    149. - containerPort: 4443
    150. name: https
    151. protocol: TCP
    152. readinessProbe:
    153. failureThreshold: 3
    154. httpGet:
    155. path: /readyz
    156. port: https
    157. scheme: HTTPS
    158. periodSeconds: 10
    159. securityContext:
    160. readOnlyRootFilesystem: true
    161. runAsNonRoot: true
    162. runAsUser: 1000
    163. volumeMounts:
    164. - mountPath: /tmp
    165. name: tmp-dir
    166. nodeSelector:
    167. kubernetes.io/os: linux
    168. priorityClassName: system-cluster-critical
    169. serviceAccountName: metrics-server
    170. volumes:
    171. - emptyDir: {}
    172. name: tmp-dir
    173. ---
    174. apiVersion: apiregistration.k8s.io/v1
    175. kind: APIService
    176. metadata:
    177. labels:
    178. k8s-app: metrics-server
    179. name: v1beta1.metrics.k8s.io
    180. spec:
    181. group: metrics.k8s.io
    182. groupPriorityMinimum: 100
    183. insecureSkipTLSVerify: true
    184. service:
    185. name: metrics-server
    186. namespace: kube-system
    187. version: v1beta1
    188. versionPriority: 100

     

    二、ingress-nginx

    kubernetes官方使用nginx做的组件

    自建集群使用裸金属安装方式

    使用

    • 给集群中需要暴露的nginx机器节点打上标签 node-role=ingress 如:

    • kubectl label node k8s-master3 node-role=ingress
      kubectl label node k8s-node1 node-role=ingress
      kubectl label node k8s-node2 node-role=ingress
      kubectl label node k8s-node3 node-role=ingress
    • 部署ingress的node节点会自动 开启 节点的 80和443 端口,保证这个机器端口不会被占用

    • 默认ingress-nginx在每个节点没有CPU、MEMORY最大配额限制;可以按照公司架构需求修改resoources.limits相关字段

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

     

    三、dashboard

    可以安装k8s的默认可视化平台

    GitHub - kubernetes/dashboard: General-purpose web UI for Kubernetes clusters

    注意:官方下载来的默认没有指定授权,使用下面创建过授权的配置

    1. # 获取dashboard访问令牌
    2. kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
    1. apiVersion: v1
    2. kind: Namespace
    3. metadata:
    4. name: kubernetes-dashboard
    5. ---
    6. apiVersion: v1
    7. kind: ServiceAccount
    8. metadata:
    9. labels:
    10. k8s-app: kubernetes-dashboard
    11. name: kubernetes-dashboard
    12. namespace: kubernetes-dashboard
    13. ---
    14. kind: Service
    15. apiVersion: v1
    16. metadata:
    17. labels:
    18. k8s-app: kubernetes-dashboard
    19. name: kubernetes-dashboard
    20. namespace: kubernetes-dashboard
    21. spec:
    22. ports:
    23. - port: 443
    24. targetPort: 8443
    25. selector:
    26. k8s-app: kubernetes-dashboard
    27. ---
    28. apiVersion: v1
    29. kind: Secret
    30. metadata:
    31. labels:
    32. k8s-app: kubernetes-dashboard
    33. name: kubernetes-dashboard-certs
    34. namespace: kubernetes-dashboard
    35. type: Opaque
    36. ---
    37. apiVersion: v1
    38. kind: Secret
    39. metadata:
    40. labels:
    41. k8s-app: kubernetes-dashboard
    42. name: kubernetes-dashboard-csrf
    43. namespace: kubernetes-dashboard
    44. type: Opaque
    45. data:
    46. csrf: ""
    47. ---
    48. apiVersion: v1
    49. kind: Secret
    50. metadata:
    51. labels:
    52. k8s-app: kubernetes-dashboard
    53. name: kubernetes-dashboard-key-holder
    54. namespace: kubernetes-dashboard
    55. type: Opaque
    56. ---
    57. kind: ConfigMap
    58. apiVersion: v1
    59. metadata:
    60. labels:
    61. k8s-app: kubernetes-dashboard
    62. name: kubernetes-dashboard-settings
    63. namespace: kubernetes-dashboard
    64. ---
    65. kind: Role
    66. apiVersion: rbac.authorization.k8s.io/v1
    67. metadata:
    68. labels:
    69. k8s-app: kubernetes-dashboard
    70. name: kubernetes-dashboard
    71. namespace: kubernetes-dashboard
    72. rules:
    73. # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
    74. - apiGroups: [""]
    75. resources: ["secrets"]
    76. resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs", "kubernetes-dashboard-csrf"]
    77. verbs: ["get", "update", "delete"]
    78. # Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
    79. - apiGroups: [""]
    80. resources: ["configmaps"]
    81. resourceNames: ["kubernetes-dashboard-settings"]
    82. verbs: ["get", "update"]
    83. # Allow Dashboard to get metrics.
    84. - apiGroups: [""]
    85. resources: ["services"]
    86. resourceNames: ["heapster", "dashboard-metrics-scraper"]
    87. verbs: ["proxy"]
    88. - apiGroups: [""]
    89. resources: ["services/proxy"]
    90. resourceNames: ["heapster", "http:heapster:", "https:heapster:", "dashboard-metrics-scraper", "http:dashboard-metrics-scraper"]
    91. verbs: ["get"]
    92. ---
    93. kind: ClusterRole
    94. apiVersion: rbac.authorization.k8s.io/v1
    95. metadata:
    96. labels:
    97. k8s-app: kubernetes-dashboard
    98. name: kubernetes-dashboard
    99. rules:
    100. # Allow Metrics Scraper to get metrics from the Metrics server
    101. - apiGroups: ["metrics.k8s.io"]
    102. resources: ["pods", "nodes"]
    103. verbs: ["get", "list", "watch"]
    104. ---
    105. apiVersion: rbac.authorization.k8s.io/v1
    106. kind: RoleBinding
    107. metadata:
    108. labels:
    109. k8s-app: kubernetes-dashboard
    110. name: kubernetes-dashboard
    111. namespace: kubernetes-dashboard
    112. roleRef:
    113. apiGroup: rbac.authorization.k8s.io
    114. kind: Role
    115. name: kubernetes-dashboard
    116. subjects:
    117. - kind: ServiceAccount
    118. name: kubernetes-dashboard
    119. namespace: kubernetes-dashboard
    120. ---
    121. kind: Deployment
    122. apiVersion: apps/v1
    123. metadata:
    124. labels:
    125. k8s-app: kubernetes-dashboard
    126. name: kubernetes-dashboard
    127. namespace: kubernetes-dashboard
    128. spec:
    129. replicas: 1
    130. revisionHistoryLimit: 10
    131. selector:
    132. matchLabels:
    133. k8s-app: kubernetes-dashboard
    134. template:
    135. metadata:
    136. labels:
    137. k8s-app: kubernetes-dashboard
    138. spec:
    139. containers:
    140. - name: kubernetes-dashboard
    141. image: kubernetesui/dashboard:v2.2.0
    142. imagePullPolicy: Always
    143. ports:
    144. - containerPort: 8443
    145. protocol: TCP
    146. args:
    147. - --auto-generate-certificates
    148. - --namespace=kubernetes-dashboard
    149. # Uncomment the following line to manually specify Kubernetes API server Host
    150. # If not specified, Dashboard will attempt to auto discover the API server and connect
    151. # to it. Uncomment only if the default does not work.
    152. # - --apiserver-host=http://my-address:port
    153. volumeMounts:
    154. - name: kubernetes-dashboard-certs
    155. mountPath: /certs
    156. # Create on-disk volume to store exec logs
    157. - mountPath: /tmp
    158. name: tmp-volume
    159. livenessProbe:
    160. httpGet:
    161. scheme: HTTPS
    162. path: /
    163. port: 8443
    164. initialDelaySeconds: 30
    165. timeoutSeconds: 30
    166. securityContext:
    167. allowPrivilegeEscalation: false
    168. readOnlyRootFilesystem: true
    169. runAsUser: 1001
    170. runAsGroup: 2001
    171. volumes:
    172. - name: kubernetes-dashboard-certs
    173. secret:
    174. secretName: kubernetes-dashboard-certs
    175. - name: tmp-volume
    176. emptyDir: {}
    177. serviceAccountName: kubernetes-dashboard
    178. nodeSelector:
    179. "kubernetes.io/os": linux
    180. # Comment the following tolerations if Dashboard must not be deployed on master
    181. tolerations:
    182. - key: node-role.kubernetes.io/master
    183. effect: NoSchedule
    184. ---
    185. kind: Service
    186. apiVersion: v1
    187. metadata:
    188. labels:
    189. k8s-app: dashboard-metrics-scraper
    190. name: dashboard-metrics-scraper
    191. namespace: kubernetes-dashboard
    192. spec:
    193. ports:
    194. - port: 8000
    195. targetPort: 8000
    196. selector:
    197. k8s-app: dashboard-metrics-scraper
    198. ---
    199. kind: Deployment
    200. apiVersion: apps/v1
    201. metadata:
    202. labels:
    203. k8s-app: dashboard-metrics-scraper
    204. name: dashboard-metrics-scraper
    205. namespace: kubernetes-dashboard
    206. spec:
    207. replicas: 1
    208. revisionHistoryLimit: 10
    209. selector:
    210. matchLabels:
    211. k8s-app: dashboard-metrics-scraper
    212. template:
    213. metadata:
    214. labels:
    215. k8s-app: dashboard-metrics-scraper
    216. annotations:
    217. seccomp.security.alpha.kubernetes.io/pod: 'runtime/default'
    218. spec:
    219. containers:
    220. - name: dashboard-metrics-scraper
    221. image: kubernetesui/metrics-scraper:v1.0.6
    222. ports:
    223. - containerPort: 8000
    224. protocol: TCP
    225. livenessProbe:
    226. httpGet:
    227. scheme: HTTP
    228. path: /
    229. port: 8000
    230. initialDelaySeconds: 30
    231. timeoutSeconds: 30
    232. volumeMounts:
    233. - mountPath: /tmp
    234. name: tmp-volume
    235. securityContext:
    236. allowPrivilegeEscalation: false
    237. readOnlyRootFilesystem: true
    238. runAsUser: 1001
    239. runAsGroup: 2001
    240. serviceAccountName: kubernetes-dashboard
    241. nodeSelector:
    242. "kubernetes.io/os": linux
    243. # Comment the following tolerations if Dashboard must not be deployed on master
    244. tolerations:
    245. - key: node-role.kubernetes.io/master
    246. effect: NoSchedule
    247. volumes:
    248. - name: tmp-volume
    249. emptyDir: {}
    250. ---
    251. apiVersion: rbac.authorization.k8s.io/v1
    252. kind: ClusterRoleBinding
    253. metadata:
    254. name: kubernetes-dashboard
    255. namespace: kubernetes-dashboard
    256. roleRef:
    257. apiGroup: rbac.authorization.k8s.io
    258. kind: ClusterRole
    259. name: cluster-admin
    260. subjects:
    261. - kind: ServiceAccount
    262. name: kubernetes-dashboard
    263. namespace: kubernetes-dashboard

    四、helm应用商店

    curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

    # helm国内源,但是版本很久没更新
    http://mirror.azure.cn/kubernetes/charts/ 

    详细的安装介绍可以参数我上一篇文章

    有兴趣的同学可以点下面链接:

    云原生(三十) | Kubernetes篇之应用商店-Helm_Lansonli的博客-CSDN博客

     


    • 📢博客主页:https://lansonli.blog.csdn.net
    • 📢欢迎点赞 👍 收藏 ⭐留言 📝 如有错误敬请指正!
    • 📢本文由 Lansonli 原创,首发于 CSDN博客🙉
    • 📢停下休息的时候不要忘了别人还在奔跑,希望大家抓紧时间学习,全力奔赴更美好的生活✨ 
  • 相关阅读:
    JUC并发编程——读写锁(基于狂神说的学习笔记)
    ubuntu中的系统消息中显卡显示llvmpipe (LLVM 10.0.0, 256 bits)
    【MySQL】Spring Boot项目基于Sharding-JDBC和MySQL主从复制实现读写分离(8千字详细教程)
    Flink写入kafka的自定义Key值
    vue2.x 和 vue3.x的区别
    测试方法学习
    ARP欺骗
    ClickHouse Senior Course Ⅴ
    10 分钟讲完 QUIC 协议。
    MyBatis: 向oracle表中插入null字段的处理
  • 原文地址:https://blog.csdn.net/xiaoweite1/article/details/125514433