当前位置:   article > 正文

k8s集群搭建clickhouse集群_kubernetes clickhouse

kubernetes clickhouse

        clickhouse-operator创建、配置和管理在kubernetes上运行的clickhouse集群。ck-operator提供如下功能:

 

  • 创建基于自定义资源ClickHouse集群规范前提
  • 自定义存储配置(VolumeClaim 模板)
  • 自定义 pod 模板
  • 为端点定制服务模板
  • ClickHouse 配置和设置(包括 Zookeeper 集成)
  • 灵活的模板
  • ClickHouse 集群扩展,包括自动模式传播
  • ClickHouse 版本升级
  • 将 ClickHouse 指标导出到 Prometheus

主要分为3步骤:安装clickhouse-operator,k8s上部署zookeeper,配置clickhouse集群

创建命名空间,命名空间保证了操作的隔离性,假设用户A和用户B分别创建了各自的命名空间,这样即使你们的服务的名字一样也不会冲突。

kubectl create ckk8s

1、安装clickhouse-operator

1)创建clickhouse-operator-install.yaml文件

vim clickhouse-operator-install.yaml

内容如下:

  1. apiVersion: apiextensions.k8s.io/v1beta1
  2. kind: CustomResourceDefinition
  3. metadata:
  4. name: clickhouseinstallations.clickhouse.altinity.com
  5. spec:
  6. group: clickhouse.altinity.com
  7. version: v1
  8. scope: Namespaced
  9. names:
  10. kind: ClickHouseInstallation
  11. singular: clickhouseinstallation
  12. plural: clickhouseinstallations
  13. shortNames:
  14. - chi
  15. additionalPrinterColumns:
  16. - name: version
  17. type: string
  18. description: Operator version
  19. priority: 1 # show in wide view
  20. JSONPath: .status.version
  21. - name: clusters
  22. type: integer
  23. description: Clusters count
  24. priority: 0 # show in standard view
  25. JSONPath: .status.clusters
  26. - name: shards
  27. type: integer
  28. description: Shards count
  29. priority: 1 # show in wide view
  30. JSONPath: .status.shards
  31. - name: hosts
  32. type: integer
  33. description: Hosts count
  34. priority: 0 # show in standard view
  35. JSONPath: .status.hosts
  36. - name: taskID
  37. type: string
  38. description: TaskID
  39. priority: 1 # show in wide view
  40. JSONPath: .status.taskID
  41. - name: status
  42. type: string
  43. description: CHI status
  44. priority: 0 # show in standard view
  45. JSONPath: .status.status
  46. - name: updated
  47. type: integer
  48. description: Updated hosts count
  49. priority: 1 # show in wide view
  50. JSONPath: .status.updated
  51. - name: added
  52. type: integer
  53. description: Added hosts count
  54. priority: 1 # show in wide view
  55. JSONPath: .status.added
  56. - name: deleted
  57. type: integer
  58. description: Hosts deleted count
  59. priority: 1 # show in wide view
  60. JSONPath: .status.deleted
  61. - name: delete
  62. type: integer
  63. description: Hosts to be deleted count
  64. priority: 1 # show in wide view
  65. JSONPath: .status.delete
  66. - name: endpoint
  67. type: string
  68. description: Client access endpoint
  69. priority: 1 # show in wide view
  70. JSONPath: .status.endpoint
  71. # TODO return to this feature later
  72. # Pruning unknown fields. FEATURE STATE: Kubernetes v1.15
  73. # Probably full specification may be needed
  74. # preserveUnknownFields: false
  75. validation:
  76. openAPIV3Schema:
  77. type: object
  78. properties:
  79. spec:
  80. type: object
  81. x-kubernetes-preserve-unknown-fields: true
  82. properties:
  83. taskID:
  84. type: string
  85. # Need to be StringBool
  86. stop:
  87. type: string
  88. enum:
  89. # List StringBoolXXX constants from model
  90. - ""
  91. - "0"
  92. - "1"
  93. - "False"
  94. - "false"
  95. - "True"
  96. - "true"
  97. - "No"
  98. - "no"
  99. - "Yes"
  100. - "yes"
  101. - "Off"
  102. - "off"
  103. - "On"
  104. - "on"
  105. - "Disable"
  106. - "disable"
  107. - "Enable"
  108. - "enable"
  109. - "Disabled"
  110. - "disabled"
  111. - "Enabled"
  112. - "enabled"
  113. # Need to be StringBool
  114. troubleshoot:
  115. type: string
  116. enum:
  117. # List StringBoolXXX constants from model
  118. - ""
  119. - "0"
  120. - "1"
  121. - "False"
  122. - "false"
  123. - "True"
  124. - "true"
  125. - "No"
  126. - "no"
  127. - "Yes"
  128. - "yes"
  129. - "Off"
  130. - "off"
  131. - "On"
  132. - "on"
  133. - "Disable"
  134. - "disable"
  135. - "Enable"
  136. - "enable"
  137. - "Disabled"
  138. - "disabled"
  139. - "Enabled"
  140. - "enabled"
  141. namespaceDomainPattern:
  142. type: string
  143. templating:
  144. type: object
  145. nullable: true
  146. properties:
  147. policy:
  148. type: string
  149. reconciling:
  150. type: object
  151. nullable: true
  152. properties:
  153. policy:
  154. type: string
  155. configMapPropagationTimeout:
  156. type: integer
  157. minimum: 0
  158. maximum: 3600
  159. cleanup:
  160. type: object
  161. nullable: true
  162. properties:
  163. unknownObjects:
  164. type: object
  165. nullable: true
  166. properties:
  167. statefulSet:
  168. type: string
  169. enum:
  170. # List ObjectsCleanupXXX constants from model
  171. - "Retain"
  172. - "Delete"
  173. pvc:
  174. type: string
  175. enum:
  176. # List ObjectsCleanupXXX constants from model
  177. - "Retain"
  178. - "Delete"
  179. configMap:
  180. type: string
  181. enum:
  182. # List ObjectsCleanupXXX constants from model
  183. - "Retain"
  184. - "Delete"
  185. service:
  186. type: string
  187. enum:
  188. # List ObjectsCleanupXXX constants from model
  189. - "Retain"
  190. - "Delete"
  191. reconcileFailedObjects:
  192. type: object
  193. nullable: true
  194. properties:
  195. statefulSet:
  196. type: string
  197. enum:
  198. # List ObjectsCleanupXXX constants from model
  199. - "Retain"
  200. - "Delete"
  201. pvc:
  202. type: string
  203. enum:
  204. # List ObjectsCleanupXXX constants from model
  205. - "Retain"
  206. - "Delete"
  207. configMap:
  208. type: string
  209. enum:
  210. # List ObjectsCleanupXXX constants from model
  211. - "Retain"
  212. - "Delete"
  213. service:
  214. type: string
  215. enum:
  216. # List ObjectsCleanupXXX constants from model
  217. - "Retain"
  218. - "Delete"
  219. defaults:
  220. type: object
  221. nullable: true
  222. properties:
  223. # Need to be StringBool
  224. replicasUseFQDN:
  225. type: string
  226. enum:
  227. # List StringBoolXXX constants from model
  228. - ""
  229. - "0"
  230. - "1"
  231. - "False"
  232. - "false"
  233. - "True"
  234. - "true"
  235. - "No"
  236. - "no"
  237. - "Yes"
  238. - "yes"
  239. - "Off"
  240. - "off"
  241. - "On"
  242. - "on"
  243. - "Disable"
  244. - "disable"
  245. - "Enable"
  246. - "enable"
  247. - "Disabled"
  248. - "disabled"
  249. - "Enabled"
  250. - "enabled"
  251. distributedDDL:
  252. type: object
  253. nullable: true
  254. properties:
  255. profile:
  256. type: string
  257. templates:
  258. type: object
  259. nullable: true
  260. properties:
  261. hostTemplate:
  262. type: string
  263. podTemplate:
  264. type: string
  265. dataVolumeClaimTemplate:
  266. type: string
  267. logVolumeClaimTemplate:
  268. type: string
  269. serviceTemplate:
  270. type: string
  271. clusterServiceTemplate:
  272. type: string
  273. shardServiceTemplate:
  274. type: string
  275. replicaServiceTemplate:
  276. type: string
  277. configuration:
  278. type: object
  279. nullable: true
  280. properties:
  281. zookeeper:
  282. type: object
  283. nullable: true
  284. properties:
  285. nodes:
  286. type: array
  287. nullable: true
  288. items:
  289. type: object
  290. #required:
  291. # - host
  292. properties:
  293. host:
  294. type: string
  295. port:
  296. type: integer
  297. minimum: 0
  298. maximum: 65535
  299. session_timeout_ms:
  300. type: integer
  301. operation_timeout_ms:
  302. type: integer
  303. root:
  304. type: string
  305. identity:
  306. type: string
  307. users:
  308. type: object
  309. nullable: true
  310. profiles:
  311. type: object
  312. nullable: true
  313. quotas:
  314. type: object
  315. nullable: true
  316. settings:
  317. type: object
  318. nullable: true
  319. files:
  320. type: object
  321. nullable: true
  322. clusters:
  323. type: array
  324. nullable: true
  325. items:
  326. type: object
  327. #required:
  328. # - name
  329. properties:
  330. name:
  331. type: string
  332. minLength: 1
  333. # See namePartClusterMaxLen const
  334. maxLength: 15
  335. pattern: "^[a-zA-Z0-9-]{0,15}$"
  336. zookeeper:
  337. type: object
  338. nullable: true
  339. properties:
  340. nodes:
  341. type: array
  342. nullable: true
  343. items:
  344. type: object
  345. #required:
  346. # - host
  347. properties:
  348. host:
  349. type: string
  350. port:
  351. type: integer
  352. minimum: 0
  353. maximum: 65535
  354. session_timeout_ms:
  355. type: integer
  356. operation_timeout_ms:
  357. type: integer
  358. root:
  359. type: string
  360. identity:
  361. type: string
  362. settings:
  363. type: object
  364. nullable: true
  365. files:
  366. type: object
  367. nullable: true
  368. templates:
  369. type: object
  370. nullable: true
  371. properties:
  372. hostTemplate:
  373. type: string
  374. podTemplate:
  375. type: string
  376. dataVolumeClaimTemplate:
  377. type: string
  378. logVolumeClaimTemplate:
  379. type: string
  380. serviceTemplate:
  381. type: string
  382. clusterServiceTemplate:
  383. type: string
  384. shardServiceTemplate:
  385. type: string
  386. replicaServiceTemplate:
  387. type: string
  388. layout:
  389. type: object
  390. nullable: true
  391. properties:
  392. # DEPRECATED - to be removed soon
  393. type:
  394. type: string
  395. shardsCount:
  396. type: integer
  397. replicasCount:
  398. type: integer
  399. shards:
  400. type: array
  401. nullable: true
  402. items:
  403. type: object
  404. properties:
  405. name:
  406. type: string
  407. minLength: 1
  408. # See namePartShardMaxLen const
  409. maxLength: 15
  410. pattern: "^[a-zA-Z0-9-]{0,15}$"
  411. # DEPRECATED - to be removed soon
  412. definitionType:
  413. type: string
  414. weight:
  415. type: integer
  416. # Need to be StringBool
  417. internalReplication:
  418. type: string
  419. enum:
  420. # List StringBoolXXX constants from model
  421. - ""
  422. - "0"
  423. - "1"
  424. - "False"
  425. - "false"
  426. - "True"
  427. - "true"
  428. - "No"
  429. - "no"
  430. - "Yes"
  431. - "yes"
  432. - "Off"
  433. - "off"
  434. - "On"
  435. - "on"
  436. - "Disable"
  437. - "disable"
  438. - "Enable"
  439. - "enable"
  440. - "Disabled"
  441. - "disabled"
  442. - "Enabled"
  443. - "enabled"
  444. settings:
  445. type: object
  446. nullable: true
  447. files:
  448. type: object
  449. nullable: true
  450. templates:
  451. type: object
  452. nullable: true
  453. properties:
  454. hostTemplate:
  455. type: string
  456. podTemplate:
  457. type: string
  458. dataVolumeClaimTemplate:
  459. type: string
  460. logVolumeClaimTemplate:
  461. type: string
  462. serviceTemplate:
  463. type: string
  464. clusterServiceTemplate:
  465. type: string
  466. shardServiceTemplate:
  467. type: string
  468. replicaServiceTemplate:
  469. type: string
  470. replicasCount:
  471. type: integer
  472. minimum: 1
  473. replicas:
  474. type: array
  475. nullable: true
  476. items:
  477. # Host
  478. type: object
  479. properties:
  480. name:
  481. type: string
  482. minLength: 1
  483. # See namePartReplicaMaxLen const
  484. maxLength: 15
  485. pattern: "^[a-zA-Z0-9-]{0,15}$"
  486. tcpPort:
  487. type: integer
  488. minimum: 1
  489. maximum: 65535
  490. httpPort:
  491. type: integer
  492. minimum: 1
  493. maximum: 65535
  494. interserverHttpPort:
  495. type: integer
  496. minimum: 1
  497. maximum: 65535
  498. settings:
  499. type: object
  500. nullable: true
  501. files:
  502. type: object
  503. nullable: true
  504. templates:
  505. type: object
  506. nullable: true
  507. properties:
  508. hostTemplate:
  509. type: string
  510. podTemplate:
  511. type: string
  512. dataVolumeClaimTemplate:
  513. type: string
  514. logVolumeClaimTemplate:
  515. type: string
  516. serviceTemplate:
  517. type: string
  518. clusterServiceTemplate:
  519. type: string
  520. shardServiceTemplate:
  521. type: string
  522. replicaServiceTemplate:
  523. type: string
  524. replicas:
  525. type: array
  526. nullable: true
  527. items:
  528. type: object
  529. properties:
  530. name:
  531. type: string
  532. minLength: 1
  533. # See namePartShardMaxLen const
  534. maxLength: 15
  535. pattern: "^[a-zA-Z0-9-]{0,15}$"
  536. settings:
  537. type: object
  538. nullable: true
  539. files:
  540. type: object
  541. nullable: true
  542. templates:
  543. type: object
  544. nullable: true
  545. properties:
  546. hostTeampate:
  547. type: string
  548. podTemplate:
  549. type: string
  550. dataVolumeClaimTemplate:
  551. type: string
  552. logVolumeClaimTemplate:
  553. type: string
  554. serviceTemplate:
  555. type: string
  556. clusterServiceTemplate:
  557. type: string
  558. shardServiceTemplate:
  559. type: string
  560. replicaServiceTemplate:
  561. type: string
  562. shardsCount:
  563. type: integer
  564. minimum: 1
  565. shards:
  566. type: array
  567. nullable: true
  568. items:
  569. # Host
  570. type: object
  571. properties:
  572. name:
  573. type: string
  574. minLength: 1
  575. # See namePartReplicaMaxLen const
  576. maxLength: 15
  577. pattern: "^[a-zA-Z0-9-]{0,15}$"
  578. tcpPort:
  579. type: integer
  580. minimum: 1
  581. maximum: 65535
  582. httpPort:
  583. type: integer
  584. minimum: 1
  585. maximum: 65535
  586. interserverHttpPort:
  587. type: integer
  588. minimum: 1
  589. maximum: 65535
  590. settings:
  591. type: object
  592. nullable: true
  593. files:
  594. type: object
  595. nullable: true
  596. templates:
  597. type: object
  598. nullable: true
  599. properties:
  600. hostTemplate:
  601. type: string
  602. podTemplate:
  603. type: string
  604. dataVolumeClaimTemplate:
  605. type: string
  606. logVolumeClaimTemplate:
  607. type: string
  608. serviceTemplate:
  609. type: string
  610. clusterServiceTemplate:
  611. type: string
  612. shardServiceTemplate:
  613. type: string
  614. replicaServiceTemplate:
  615. type: string
  616. templates:
  617. type: object
  618. nullable: true
  619. properties:
  620. hostTemplates:
  621. type: array
  622. nullable: true
  623. items:
  624. type: object
  625. #required:
  626. # - name
  627. properties:
  628. name:
  629. type: string
  630. portDistribution:
  631. type: array
  632. nullable: true
  633. items:
  634. type: object
  635. #required:
  636. # - type
  637. properties:
  638. type:
  639. type: string
  640. enum:
  641. # List PortDistributionXXX constants
  642. - ""
  643. - "Unspecified"
  644. - "ClusterScopeIndex"
  645. spec:
  646. # Host
  647. type: object
  648. properties:
  649. name:
  650. type: string
  651. minLength: 1
  652. # See namePartReplicaMaxLen const
  653. maxLength: 15
  654. pattern: "^[a-zA-Z0-9-]{0,15}$"
  655. tcpPort:
  656. type: integer
  657. minimum: 1
  658. maximum: 65535
  659. httpPort:
  660. type: integer
  661. minimum: 1
  662. maximum: 65535
  663. interserverHttpPort:
  664. type: integer
  665. minimum: 1
  666. maximum: 65535
  667. settings:
  668. type: object
  669. nullable: true
  670. files:
  671. type: object
  672. nullable: true
  673. templates:
  674. type: object
  675. nullable: true
  676. properties:
  677. hostTemplate:
  678. type: string
  679. podTemplate:
  680. type: string
  681. dataVolumeClaimTemplate:
  682. type: string
  683. logVolumeClaimTemplate:
  684. type: string
  685. serviceTemplate:
  686. type: string
  687. clusterServiceTemplate:
  688. type: string
  689. shardServiceTemplate:
  690. type: string
  691. replicaServiceTemplate:
  692. type: string
  693. podTemplates:
  694. type: array
  695. nullable: true
  696. items:
  697. type: object
  698. #required:
  699. # - name
  700. properties:
  701. name:
  702. type: string
  703. generateName:
  704. type: string
  705. zone:
  706. type: object
  707. #required:
  708. # - values
  709. properties:
  710. key:
  711. type: string
  712. values:
  713. type: array
  714. nullable: true
  715. items:
  716. type: string
  717. distribution:
  718. # DEPRECATED
  719. type: string
  720. enum:
  721. - ""
  722. - "Unspecified"
  723. - "OnePerHost"
  724. podDistribution:
  725. type: array
  726. nullable: true
  727. items:
  728. type: object
  729. #required:
  730. # - type
  731. properties:
  732. type:
  733. type: string
  734. enum:
  735. # List PodDistributionXXX constants
  736. - ""
  737. - "Unspecified"
  738. - "ClickHouseAntiAffinity"
  739. - "ShardAntiAffinity"
  740. - "ReplicaAntiAffinity"
  741. - "AnotherNamespaceAntiAffinity"
  742. - "AnotherClickHouseInstallationAntiAffinity"
  743. - "AnotherClusterAntiAffinity"
  744. - "MaxNumberPerNode"
  745. - "NamespaceAffinity"
  746. - "ClickHouseInstallationAffinity"
  747. - "ClusterAffinity"
  748. - "ShardAffinity"
  749. - "ReplicaAffinity"
  750. - "PreviousTailAffinity"
  751. - "CircularReplication"
  752. scope:
  753. type: string
  754. enum:
  755. # list PodDistributionScopeXXX constants
  756. - ""
  757. - "Unspecified"
  758. - "Shard"
  759. - "Replica"
  760. - "Cluster"
  761. - "ClickHouseInstallation"
  762. - "Namespace"
  763. number:
  764. type: integer
  765. minimum: 0
  766. maximum: 65535
  767. spec:
  768. # TODO specify PodSpec
  769. type: object
  770. nullable: true
  771. volumeClaimTemplates:
  772. type: array
  773. nullable: true
  774. items:
  775. type: object
  776. #required:
  777. # - name
  778. # - spec
  779. properties:
  780. name:
  781. type: string
  782. reclaimPolicy:
  783. type: string
  784. enum:
  785. - ""
  786. - "Retain"
  787. - "Delete"
  788. metadata:
  789. type: object
  790. nullable: true
  791. spec:
  792. # TODO specify PersistentVolumeClaimSpec
  793. type: object
  794. nullable: true
  795. serviceTemplates:
  796. type: array
  797. nullable: true
  798. items:
  799. type: object
  800. #required:
  801. # - name
  802. # - spec
  803. properties:
  804. name:
  805. type: string
  806. generateName:
  807. type: string
  808. metadata:
  809. # TODO specify ObjectMeta
  810. type: object
  811. nullable: true
  812. spec:
  813. # TODO specify ServiceSpec
  814. type: object
  815. nullable: true
  816. useTemplates:
  817. type: array
  818. nullable: true
  819. items:
  820. type: object
  821. #required:
  822. # - name
  823. properties:
  824. name:
  825. type: string
  826. namespace:
  827. type: string
  828. useType:
  829. type: string
  830. enum:
  831. # List useTypeXXX constants from model
  832. - ""
  833. - "merge"
  834. ---
  835. apiVersion: apiextensions.k8s.io/v1beta1
  836. kind: CustomResourceDefinition
  837. metadata:
  838. name: clickhouseinstallationtemplates.clickhouse.altinity.com
  839. spec:
  840. group: clickhouse.altinity.com
  841. version: v1
  842. scope: Namespaced
  843. names:
  844. kind: ClickHouseInstallationTemplate
  845. singular: clickhouseinstallationtemplate
  846. plural: clickhouseinstallationtemplates
  847. shortNames:
  848. - chit
  849. additionalPrinterColumns:
  850. - name: version
  851. type: string
  852. description: Operator version
  853. priority: 1 # show in wide view
  854. JSONPath: .status.version
  855. - name: clusters
  856. type: integer
  857. description: Clusters count
  858. priority: 0 # show in standard view
  859. JSONPath: .status.clusters
  860. - name: shards
  861. type: integer
  862. description: Shards count
  863. priority: 1 # show in wide view
  864. JSONPath: .status.shards
  865. - name: hosts
  866. type: integer
  867. description: Hosts count
  868. priority: 0 # show in standard view
  869. JSONPath: .status.hosts
  870. - name: taskID
  871. type: string
  872. description: TaskID
  873. priority: 1 # show in wide view
  874. JSONPath: .status.taskID
  875. - name: status
  876. type: string
  877. description: CHI status
  878. priority: 0 # show in standard view
  879. JSONPath: .status.status
  880. - name: updated
  881. type: integer
  882. description: Updated hosts count
  883. priority: 1 # show in wide view
  884. JSONPath: .status.updated
  885. - name: added
  886. type: integer
  887. description: Added hosts count
  888. priority: 1 # show in wide view
  889. JSONPath: .status.added
  890. - name: deleted
  891. type: integer
  892. description: Hosts deleted count
  893. priority: 1 # show in wide view
  894. JSONPath: .status.deleted
  895. - name: delete
  896. type: integer
  897. description: Hosts to be deleted count
  898. priority: 1 # show in wide view
  899. JSONPath: .status.delete
  900. - name: endpoint
  901. type: string
  902. description: Client access endpoint
  903. priority: 1 # show in wide view
  904. JSONPath: .status.endpoint
  905. # TODO return to this feature later
  906. # Pruning unknown fields. FEATURE STATE: Kubernetes v1.15
  907. # Probably full specification may be needed
  908. # preserveUnknownFields: false
  909. validation:
  910. openAPIV3Schema:
  911. type: object
  912. properties:
  913. spec:
  914. type: object
  915. x-kubernetes-preserve-unknown-fields: true
  916. properties:
  917. taskID:
  918. type: string
  919. # Need to be StringBool
  920. stop:
  921. type: string
  922. enum:
  923. # List StringBoolXXX constants from model
  924. - ""
  925. - "0"
  926. - "1"
  927. - "False"
  928. - "false"
  929. - "True"
  930. - "true"
  931. - "No"
  932. - "no"
  933. - "Yes"
  934. - "yes"
  935. - "Off"
  936. - "off"
  937. - "On"
  938. - "on"
  939. - "Disable"
  940. - "disable"
  941. - "Enable"
  942. - "enable"
  943. - "Disabled"
  944. - "disabled"
  945. - "Enabled"
  946. - "enabled"
  947. # Need to be StringBool
  948. troubleshoot:
  949. type: string
  950. enum:
  951. # List StringBoolXXX constants from model
  952. - ""
  953. - "0"
  954. - "1"
  955. - "False"
  956. - "false"
  957. - "True"
  958. - "true"
  959. - "No"
  960. - "no"
  961. - "Yes"
  962. - "yes"
  963. - "Off"
  964. - "off"
  965. - "On"
  966. - "on"
  967. - "Disable"
  968. - "disable"
  969. - "Enable"
  970. - "enable"
  971. - "Disabled"
  972. - "disabled"
  973. - "Enabled"
  974. - "enabled"
  975. namespaceDomainPattern:
  976. type: string
  977. templating:
  978. type: object
  979. nullable: true
  980. properties:
  981. policy:
  982. type: string
  983. reconciling:
  984. type: object
  985. nullable: true
  986. properties:
  987. policy:
  988. type: string
  989. configMapPropagationTimeout:
  990. type: integer
  991. minimum: 0
  992. maximum: 3600
  993. cleanup:
  994. type: object
  995. nullable: true
  996. properties:
  997. unknownObjects:
  998. type: object
  999. nullable: true
  1000. properties:
  1001. statefulSet:
  1002. type: string
  1003. enum:
  1004. # List ObjectsCleanupXXX constants from model
  1005. - "Retain"
  1006. - "Delete"
  1007. pvc:
  1008. type: string
  1009. enum:
  1010. # List ObjectsCleanupXXX constants from model
  1011. - "Retain"
  1012. - "Delete"
  1013. configMap:
  1014. type: string
  1015. enum:
  1016. # List ObjectsCleanupXXX constants from model
  1017. - "Retain"
  1018. - "Delete"
  1019. service:
  1020. type: string
  1021. enum:
  1022. # List ObjectsCleanupXXX constants from model
  1023. - "Retain"
  1024. - "Delete"
  1025. reconcileFailedObjects:
  1026. type: object
  1027. nullable: true
  1028. properties:
  1029. statefulSet:
  1030. type: string
  1031. enum:
  1032. # List ObjectsCleanupXXX constants from model
  1033. - "Retain"
  1034. - "Delete"
  1035. pvc:
  1036. type: string
  1037. enum:
  1038. # List ObjectsCleanupXXX constants from model
  1039. - "Retain"
  1040. - "Delete"
  1041. configMap:
  1042. type: string
  1043. enum:
  1044. # List ObjectsCleanupXXX constants from model
  1045. - "Retain"
  1046. - "Delete"
  1047. service:
  1048. type: string
  1049. enum:
  1050. # List ObjectsCleanupXXX constants from model
  1051. - "Retain"
  1052. - "Delete"
  1053. defaults:
  1054. type: object
  1055. nullable: true
  1056. properties:
  1057. # Need to be StringBool
  1058. replicasUseFQDN:
  1059. type: string
  1060. enum:
  1061. # List StringBoolXXX constants from model
  1062. - ""
  1063. - "0"
  1064. - "1"
  1065. - "False"
  1066. - "false"
  1067. - "True"
  1068. - "true"
  1069. - "No"
  1070. - "no"
  1071. - "Yes"
  1072. - "yes"
  1073. - "Off"
  1074. - "off"
  1075. - "On"
  1076. - "on"
  1077. - "Disable"
  1078. - "disable"
  1079. - "Enable"
  1080. - "enable"
  1081. - "Disabled"
  1082. - "disabled"
  1083. - "Enabled"
  1084. - "enabled"
  1085. distributedDDL:
  1086. type: object
  1087. nullable: true
  1088. properties:
  1089. profile:
  1090. type: string
  1091. templates:
  1092. type: object
  1093. nullable: true
  1094. properties:
  1095. hostTemplate:
  1096. type: string
  1097. podTemplate:
  1098. type: string
  1099. dataVolumeClaimTemplate:
  1100. type: string
  1101. logVolumeClaimTemplate:
  1102. type: string
  1103. serviceTemplate:
  1104. type: string
  1105. clusterServiceTemplate:
  1106. type: string
  1107. shardServiceTemplate:
  1108. type: string
  1109. replicaServiceTemplate:
  1110. type: string
  1111. configuration:
  1112. type: object
  1113. nullable: true
  1114. properties:
  1115. zookeeper:
  1116. type: object
  1117. nullable: true
  1118. properties:
  1119. nodes:
  1120. type: array
  1121. nullable: true
  1122. items:
  1123. type: object
  1124. #required:
  1125. # - host
  1126. properties:
  1127. host:
  1128. type: string
  1129. port:
  1130. type: integer
  1131. minimum: 0
  1132. maximum: 65535
  1133. session_timeout_ms:
  1134. type: integer
  1135. operation_timeout_ms:
  1136. type: integer
  1137. root:
  1138. type: string
  1139. identity:
  1140. type: string
  1141. users:
  1142. type: object
  1143. nullable: true
  1144. profiles:
  1145. type: object
  1146. nullable: true
  1147. quotas:
  1148. type: object
  1149. nullable: true
  1150. settings:
  1151. type: object
  1152. nullable: true
  1153. files:
  1154. type: object
  1155. nullable: true
  1156. clusters:
  1157. type: array
  1158. nullable: true
  1159. items:
  1160. type: object
  1161. #required:
  1162. # - name
  1163. properties:
  1164. name:
  1165. type: string
  1166. minLength: 1
  1167. # See namePartClusterMaxLen const
  1168. maxLength: 15
  1169. pattern: "^[a-zA-Z0-9-]{0,15}$"
  1170. zookeeper:
  1171. type: object
  1172. nullable: true
  1173. properties:
  1174. nodes:
  1175. type: array
  1176. nullable: true
  1177. items:
  1178. type: object
  1179. #required:
  1180. # - host
  1181. properties:
  1182. host:
  1183. type: string
  1184. port:
  1185. type: integer
  1186. minimum: 0
  1187. maximum: 65535
  1188. session_timeout_ms:
  1189. type: integer
  1190. operation_timeout_ms:
  1191. type: integer
  1192. root:
  1193. type: string
  1194. identity:
  1195. type: string
  1196. settings:
  1197. type: object
  1198. nullable: true
  1199. files:
  1200. type: object
  1201. nullable: true
  1202. templates:
  1203. type: object
  1204. nullable: true
  1205. properties:
  1206. hostTemplate:
  1207. type: string
  1208. podTemplate:
  1209. type: string
  1210. dataVolumeClaimTemplate:
  1211. type: string
  1212. logVolumeClaimTemplate:
  1213. type: string
  1214. serviceTemplate:
  1215. type: string
  1216. clusterServiceTemplate:
  1217. type: string
  1218. shardServiceTemplate:
  1219. type: string
  1220. replicaServiceTemplate:
  1221. type: string
  1222. layout:
  1223. type: object
  1224. nullable: true
  1225. properties:
  1226. # DEPRECATED - to be removed soon
  1227. type:
  1228. type: string
  1229. shardsCount:
  1230. type: integer
  1231. replicasCount:
  1232. type: integer
  1233. shards:
  1234. type: array
  1235. nullable: true
  1236. items:
  1237. type: object
  1238. properties:
  1239. name:
  1240. type: string
  1241. minLength: 1
  1242. # See namePartShardMaxLen const
  1243. maxLength: 15
  1244. pattern: "^[a-zA-Z0-9-]{0,15}$"
  1245. # DEPRECATED - to be removed soon
  1246. definitionType:
  1247. type: string
  1248. weight:
  1249. type: integer
  1250. # Need to be StringBool
  1251. internalReplication:
  1252. type: string
  1253. enum:
  1254. # List StringBoolXXX constants from model
  1255. - ""
  1256. - "0"
  1257. - "1"
  1258. - "False"
  1259. - "false"
  1260. - "True"
  1261. - "true"
  1262. - "No"
  1263. - "no"
  1264. - "Yes"
  1265. - "yes"
  1266. - "Off"
  1267. - "off"
  1268. - "On"
  1269. - "on"
  1270. - "Disable"
  1271. - "disable"
  1272. - "Enable"
  1273. - "enable"
  1274. - "Disabled"
  1275. - "disabled"
  1276. - "Enabled"
  1277. - "enabled"
  1278. settings:
  1279. type: object
  1280. nullable: true
  1281. files:
  1282. type: object
  1283. nullable: true
  1284. templates:
  1285. type: object
  1286. nullable: true
  1287. properties:
  1288. hostTemplate:
  1289. type: string
  1290. podTemplate:
  1291. type: string
  1292. dataVolumeClaimTemplate:
  1293. type: string
  1294. logVolumeClaimTemplate:
  1295. type: string
  1296. serviceTemplate:
  1297. type: string
  1298. clusterServiceTemplate:
  1299. type: string
  1300. shardServiceTemplate:
  1301. type: string
  1302. replicaServiceTemplate:
  1303. type: string
  1304. replicasCount:
  1305. type: integer
  1306. minimum: 1
  1307. replicas:
  1308. type: array
  1309. nullable: true
  1310. items:
  1311. # Host
  1312. type: object
  1313. properties:
  1314. name:
  1315. type: string
  1316. minLength: 1
  1317. # See namePartReplicaMaxLen const
  1318. maxLength: 15
  1319. pattern: "^[a-zA-Z0-9-]{0,15}$"
  1320. tcpPort:
  1321. type: integer
  1322. minimum: 1
  1323. maximum: 65535
  1324. httpPort:
  1325. type: integer
  1326. minimum: 1
  1327. maximum: 65535
  1328. interserverHttpPort:
  1329. type: integer
  1330. minimum: 1
  1331. maximum: 65535
  1332. settings:
  1333. type: object
  1334. nullable: true
  1335. files:
  1336. type: object
  1337. nullable: true
  1338. templates:
  1339. type: object
  1340. nullable: true
  1341. properties:
  1342. hostTemplate:
  1343. type: string
  1344. podTemplate:
  1345. type: string
  1346. dataVolumeClaimTemplate:
  1347. type: string
  1348. logVolumeClaimTemplate:
  1349. type: string
  1350. serviceTemplate:
  1351. type: string
  1352. clusterServiceTemplate:
  1353. type: string
  1354. shardServiceTemplate:
  1355. type: string
  1356. replicaServiceTemplate:
  1357. type: string
  1358. replicas:
  1359. type: array
  1360. nullable: true
  1361. items:
  1362. type: object
  1363. properties:
  1364. name:
  1365. type: string
  1366. minLength: 1
  1367. # See namePartShardMaxLen const
  1368. maxLength: 15
  1369. pattern: "^[a-zA-Z0-9-]{0,15}$"
  1370. settings:
  1371. type: object
  1372. nullable: true
  1373. files:
  1374. type: object
  1375. nullable: true
  1376. templates:
  1377. type: object
  1378. nullable: true
  1379. properties:
  1380. hostTeampate:
  1381. type: string
  1382. podTemplate:
  1383. type: string
  1384. dataVolumeClaimTemplate:
  1385. type: string
  1386. logVolumeClaimTemplate:
  1387. type: string
  1388. serviceTemplate:
  1389. type: string
  1390. clusterServiceTemplate:
  1391. type: string
  1392. shardServiceTemplate:
  1393. type: string
  1394. replicaServiceTemplate:
  1395. type: string
  1396. shardsCount:
  1397. type: integer
  1398. minimum: 1
  1399. shards:
  1400. type: array
  1401. nullable: true
  1402. items:
  1403. # Host
  1404. type: object
  1405. properties:
  1406. name:
  1407. type: string
  1408. minLength: 1
  1409. # See namePartReplicaMaxLen const
  1410. maxLength: 15
  1411. pattern: "^[a-zA-Z0-9-]{0,15}$"
  1412. tcpPort:
  1413. type: integer
  1414. minimum: 1
  1415. maximum: 65535
  1416. httpPort:
  1417. type: integer
  1418. minimum: 1
  1419. maximum: 65535
  1420. interserverHttpPort:
  1421. type: integer
  1422. minimum: 1
  1423. maximum: 65535
  1424. settings:
  1425. type: object
  1426. nullable: true
  1427. files:
  1428. type: object
  1429. nullable: true
  1430. templates:
  1431. type: object
  1432. nullable: true
  1433. properties:
  1434. hostTemplate:
  1435. type: string
  1436. podTemplate:
  1437. type: string
  1438. dataVolumeClaimTemplate:
  1439. type: string
  1440. logVolumeClaimTemplate:
  1441. type: string
  1442. serviceTemplate:
  1443. type: string
  1444. clusterServiceTemplate:
  1445. type: string
  1446. shardServiceTemplate:
  1447. type: string
  1448. replicaServiceTemplate:
  1449. type: string
  1450. templates:
  1451. type: object
  1452. nullable: true
  1453. properties:
  1454. hostTemplates:
  1455. type: array
  1456. nullable: true
  1457. items:
  1458. type: object
  1459. #required:
  1460. # - name
  1461. properties:
  1462. name:
  1463. type: string
  1464. portDistribution:
  1465. type: array
  1466. nullable: true
  1467. items:
  1468. type: object
  1469. #required:
  1470. # - type
  1471. properties:
  1472. type:
  1473. type: string
  1474. enum:
  1475. # List PortDistributionXXX constants
  1476. - ""
  1477. - "Unspecified"
  1478. - "ClusterScopeIndex"
  1479. spec:
  1480. # Host
  1481. type: object
  1482. properties:
  1483. name:
  1484. type: string
  1485. minLength: 1
  1486. # See namePartReplicaMaxLen const
  1487. maxLength: 15
  1488. pattern: "^[a-zA-Z0-9-]{0,15}$"
  1489. tcpPort:
  1490. type: integer
  1491. minimum: 1
  1492. maximum: 65535
  1493. httpPort:
  1494. type: integer
  1495. minimum: 1
  1496. maximum: 65535
  1497. interserverHttpPort:
  1498. type: integer
  1499. minimum: 1
  1500. maximum: 65535
  1501. settings:
  1502. type: object
  1503. nullable: true
  1504. files:
  1505. type: object
  1506. nullable: true
  1507. templates:
  1508. type: object
  1509. nullable: true
  1510. properties:
  1511. hostTemplate:
  1512. type: string
  1513. podTemplate:
  1514. type: string
  1515. dataVolumeClaimTemplate:
  1516. type: string
  1517. logVolumeClaimTemplate:
  1518. type: string
  1519. serviceTemplate:
  1520. type: string
  1521. clusterServiceTemplate:
  1522. type: string
  1523. shardServiceTemplate:
  1524. type: string
  1525. replicaServiceTemplate:
  1526. type: string
  1527. podTemplates:
  1528. type: array
  1529. nullable: true
  1530. items:
  1531. type: object
  1532. #required:
  1533. # - name
  1534. properties:
  1535. name:
  1536. type: string
  1537. generateName:
  1538. type: string
  1539. zone:
  1540. type: object
  1541. #required:
  1542. # - values
  1543. properties:
  1544. key:
  1545. type: string
  1546. values:
  1547. type: array
  1548. nullable: true
  1549. items:
  1550. type: string
  1551. distribution:
  1552. # DEPRECATED
  1553. type: string
  1554. enum:
  1555. - ""
  1556. - "Unspecified"
  1557. - "OnePerHost"
  1558. podDistribution:
  1559. type: array
  1560. nullable: true
  1561. items:
  1562. type: object
  1563. #required:
  1564. # - type
  1565. properties:
  1566. type:
  1567. type: string
  1568. enum:
  1569. # List PodDistributionXXX constants
  1570. - ""
  1571. - "Unspecified"
  1572. - "ClickHouseAntiAffinity"
  1573. - "ShardAntiAffinity"
  1574. - "ReplicaAntiAffinity"
  1575. - "AnotherNamespaceAntiAffinity"
  1576. - "AnotherClickHouseInstallationAntiAffinity"
  1577. - "AnotherClusterAntiAffinity"
  1578. - "MaxNumberPerNode"
  1579. - "NamespaceAffinity"
  1580. - "ClickHouseInstallationAffinity"
  1581. - "ClusterAffinity"
  1582. - "ShardAffinity"
  1583. - "ReplicaAffinity"
  1584. - "PreviousTailAffinity"
  1585. - "CircularReplication"
  1586. scope:
  1587. type: string
  1588. enum:
  1589. # list PodDistributionScopeXXX constants
  1590. - ""
  1591. - "Unspecified"
  1592. - "Shard"
  1593. - "Replica"
  1594. - "Cluster"
  1595. - "ClickHouseInstallation"
  1596. - "Namespace"
  1597. number:
  1598. type: integer
  1599. minimum: 0
  1600. maximum: 65535
  1601. spec:
  1602. # TODO specify PodSpec
  1603. type: object
  1604. nullable: true
  1605. volumeClaimTemplates:
  1606. type: array
  1607. nullable: true
  1608. items:
  1609. type: object
  1610. #required:
  1611. # - name
  1612. # - spec
  1613. properties:
  1614. name:
  1615. type: string
  1616. reclaimPolicy:
  1617. type: string
  1618. enum:
  1619. - ""
  1620. - "Retain"
  1621. - "Delete"
  1622. metadata:
  1623. type: object
  1624. nullable: true
  1625. spec:
  1626. # TODO specify PersistentVolumeClaimSpec
  1627. type: object
  1628. nullable: true
  1629. serviceTemplates:
  1630. type: array
  1631. nullable: true
  1632. items:
  1633. type: object
  1634. #required:
  1635. # - name
  1636. # - spec
  1637. properties:
  1638. name:
  1639. type: string
  1640. generateName:
  1641. type: string
  1642. metadata:
  1643. # TODO specify ObjectMeta
  1644. type: object
  1645. nullable: true
  1646. spec:
  1647. # TODO specify ServiceSpec
  1648. type: object
  1649. nullable: true
  1650. useTemplates:
  1651. type: array
  1652. nullable: true
  1653. items:
  1654. type: object
  1655. #required:
  1656. # - name
  1657. properties:
  1658. name:
  1659. type: string
  1660. namespace:
  1661. type: string
  1662. useType:
  1663. type: string
  1664. enum:
  1665. # List useTypeXXX constants from model
  1666. - ""
  1667. - "merge"
  1668. ---
  1669. apiVersion: apiextensions.k8s.io/v1beta1
  1670. kind: CustomResourceDefinition
  1671. metadata:
  1672. name: clickhouseoperatorconfigurations.clickhouse.altinity.com
  1673. spec:
  1674. group: clickhouse.altinity.com
  1675. version: v1
  1676. scope: Namespaced
  1677. names:
  1678. kind: ClickHouseOperatorConfiguration
  1679. singular: clickhouseoperatorconfiguration
  1680. plural: clickhouseoperatorconfigurations
  1681. shortNames:
  1682. - chopconf
  1683. additionalPrinterColumns:
  1684. - name: namespaces
  1685. type: string
  1686. description: Watch namespaces
  1687. priority: 0 # show in standard view
  1688. JSONPath: .status
  1689. # TODO return to this feature later
  1690. # Pruning unknown fields. FEATURE STATE: Kubernetes v1.15
  1691. # Probably full specification may be needed
  1692. # preserveUnknownFields: false
  1693. validation:
  1694. openAPIV3Schema:
  1695. type: object
  1696. properties:
  1697. spec:
  1698. type: object
  1699. x-kubernetes-preserve-unknown-fields: true
  1700. properties:
  1701. watchNamespaces:
  1702. type: array
  1703. items:
  1704. type: string
  1705. chCommonConfigsPath:
  1706. type: string
  1707. chHostConfigsPath:
  1708. type: string
  1709. chUsersConfigsPath:
  1710. type: string
  1711. chiTemplatesPath:
  1712. type: string
  1713. statefulSetUpdateTimeout:
  1714. type: integer
  1715. statefulSetUpdatePollPeriod:
  1716. type: integer
  1717. onStatefulSetCreateFailureAction:
  1718. type: string
  1719. onStatefulSetUpdateFailureAction:
  1720. type: string
  1721. chConfigUserDefaultProfile:
  1722. type: string
  1723. chConfigUserDefaultQuota:
  1724. type: string
  1725. chConfigUserDefaultNetworksIP:
  1726. type: array
  1727. items:
  1728. type: string
  1729. chConfigUserDefaultPassword:
  1730. type: string
  1731. chConfigNetworksHostRegexpTemplate:
  1732. type: string
  1733. chUsername:
  1734. type: string
  1735. chPassword:
  1736. type: string
  1737. chCredentialsSecretNamespace:
  1738. type: string
  1739. chCredentialsSecretName:
  1740. type: string
  1741. chPort:
  1742. type: integer
  1743. minimum: 1
  1744. maximum: 65535
  1745. logtostderr:
  1746. type: string
  1747. alsologtostderr:
  1748. type: string
  1749. v:
  1750. type: string
  1751. stderrthreshold:
  1752. type: string
  1753. vmodule:
  1754. type: string
  1755. log_backtrace_at:
  1756. type: string
  1757. reconcileThreadsNumber:
  1758. type: integer
  1759. minimum: 1
  1760. maximum: 65535
  1761. reconcileWaitExclude:
  1762. type: string
  1763. reconcileWaitInclude:
  1764. type: string
  1765. excludeFromPropagationLabels:
  1766. type: array
  1767. items:
  1768. type: string
  1769. appendScopeLabels:
  1770. type: string
  1771. enum:
  1772. # List StringBoolXXX constants from model
  1773. - ""
  1774. - "0"
  1775. - "1"
  1776. - "False"
  1777. - "false"
  1778. - "True"
  1779. - "true"
  1780. - "No"
  1781. - "no"
  1782. - "Yes"
  1783. - "yes"
  1784. - "Off"
  1785. - "off"
  1786. - "On"
  1787. - "on"
  1788. - "Disable"
  1789. - "disable"
  1790. - "Enable"
  1791. - "enable"
  1792. - "Disabled"
  1793. - "disabled"
  1794. - "Enabled"
  1795. - "enabled"
  1796. ---
  1797. # Possible Template Parameters:
  1798. #
  1799. # kube-system
  1800. #
  1801. # Setup ServiceAccount
  1802. # ServiceAccount would be created in kubectl-specified namespace
  1803. apiVersion: v1
  1804. kind: ServiceAccount
  1805. metadata:
  1806. name: clickhouse-operator
  1807. namespace: kube-system
  1808. ---
  1809. apiVersion: rbac.authorization.k8s.io/v1
  1810. kind: ClusterRole
  1811. metadata:
  1812. name: clickhouse-operator-kube-system
  1813. rules:
  1814. - apiGroups:
  1815. - ""
  1816. resources:
  1817. - configmaps
  1818. - services
  1819. verbs:
  1820. - create
  1821. - delete
  1822. - get
  1823. - patch
  1824. - update
  1825. - apiGroups:
  1826. - ""
  1827. resources:
  1828. - events
  1829. verbs:
  1830. - create
  1831. - apiGroups:
  1832. - ""
  1833. resources:
  1834. - persistentvolumeclaims
  1835. verbs:
  1836. - delete
  1837. - get
  1838. - list
  1839. - patch
  1840. - update
  1841. - watch
  1842. - apiGroups:
  1843. - ""
  1844. resources:
  1845. - persistentvolumes
  1846. - pods
  1847. verbs:
  1848. - get
  1849. - list
  1850. - patch
  1851. - update
  1852. - watch
  1853. - apiGroups:
  1854. - apps
  1855. resources:
  1856. - statefulsets
  1857. verbs:
  1858. - create
  1859. - delete
  1860. - get
  1861. - patch
  1862. - update
  1863. - apiGroups:
  1864. - clickhouse.altinity.com
  1865. resources:
  1866. - clickhouseinstallations
  1867. verbs:
  1868. - delete
  1869. - get
  1870. - patch
  1871. - update
  1872. - apiGroups:
  1873. - apps
  1874. resourceNames:
  1875. - clickhouse-operator
  1876. resources:
  1877. - deployments
  1878. verbs:
  1879. - get
  1880. - patch
  1881. - update
  1882. - delete
  1883. - apiGroups:
  1884. - apps
  1885. resources:
  1886. - replicasets
  1887. verbs:
  1888. - delete
  1889. - get
  1890. - patch
  1891. - update
  1892. - apiGroups:
  1893. - ""
  1894. resources:
  1895. - configmaps
  1896. - endpoints
  1897. - services
  1898. verbs:
  1899. - get
  1900. - list
  1901. - watch
  1902. - apiGroups:
  1903. - apps
  1904. resources:
  1905. - statefulsets
  1906. verbs:
  1907. - get
  1908. - list
  1909. - watch
  1910. - apiGroups:
  1911. - clickhouse.altinity.com
  1912. resources:
  1913. - clickhouseinstallations
  1914. - clickhouseinstallationtemplates
  1915. - clickhouseoperatorconfigurations
  1916. verbs:
  1917. - get
  1918. - list
  1919. - watch
  1920. ---
  1921. # Setup ClusterRoleBinding between ClusterRole and ServiceAccount.
  1922. # ClusterRoleBinding is namespace-less and must have unique name
  1923. apiVersion: rbac.authorization.k8s.io/v1
  1924. kind: ClusterRoleBinding
  1925. metadata:
  1926. name: clickhouse-operator-kube-system
  1927. roleRef:
  1928. apiGroup: rbac.authorization.k8s.io
  1929. kind: ClusterRole
  1930. name: clickhouse-operator-kube-system
  1931. subjects:
  1932. - kind: ServiceAccount
  1933. name: clickhouse-operator
  1934. namespace: kube-system
  1935. ---
  1936. # Possible Template Parameters:
  1937. #
  1938. # kube-system
  1939. # altinity/clickhouse-operator:0.15.0
  1940. # etc-clickhouse-operator-files
  1941. #
  1942. apiVersion: v1
  1943. kind: ConfigMap
  1944. metadata:
  1945. name: etc-clickhouse-operator-files
  1946. namespace: kube-system
  1947. labels:
  1948. app: clickhouse-operator
  1949. data:
  1950. config.yaml: |
  1951. ################################################
  1952. ##
  1953. ## Watch Namespaces Section
  1954. ##
  1955. ################################################
  1956. # List of namespaces where clickhouse-operator watches for events.
  1957. # Concurrently running operators should watch on different namespaces
  1958. #watchNamespaces:
  1959. # - dev
  1960. # - test
  1961. # - info
  1962. # - onemore
  1963. ################################################
  1964. ##
  1965. ## Additional Configuration Files Section
  1966. ##
  1967. ################################################
  1968. # Path to folder where ClickHouse configuration files common for all instances within CHI are located.
  1969. chCommonConfigsPath: config.d
  1970. # Path to folder where ClickHouse configuration files unique for each instance (host) within CHI are located.
  1971. chHostConfigsPath: conf.d
  1972. # Path to folder where ClickHouse configuration files with users settings are located.
  1973. # Files are common for all instances within CHI
  1974. chUsersConfigsPath: users.d
  1975. # Path to folder where ClickHouseInstallation .yaml manifests are located.
  1976. # Manifests are applied in sorted alpha-numeric order
  1977. chiTemplatesPath: templates.d
  1978. ################################################
  1979. ##
  1980. ## Cluster Create/Update/Delete Objects Section
  1981. ##
  1982. ################################################
  1983. # How many seconds to wait for created/updated StatefulSet to be Ready
  1984. statefulSetUpdateTimeout: 300
  1985. # How many seconds to wait between checks for created/updated StatefulSet status
  1986. statefulSetUpdatePollPeriod: 5
  1987. # What to do in case created StatefulSet is not in Ready after `statefulSetUpdateTimeout` seconds
  1988. # Possible options:
  1989. # 1. abort - do nothing, just break the process and wait for admin
  1990. # 2. delete - delete newly created problematic StatefulSet
  1991. # 3. ignore - ignore error, pretend nothing happened and move on to the next StatefulSet
  1992. onStatefulSetCreateFailureAction: ignore
  1993. # What to do in case updated StatefulSet is not in Ready after `statefulSetUpdateTimeout` seconds
  1994. # Possible options:
  1995. # 1. abort - do nothing, just break the process and wait for admin
  1996. # 2. rollback - delete Pod and rollback StatefulSet to previous Generation.
  1997. # Pod would be recreated by StatefulSet based on rollback-ed configuration
  1998. # 3. ignore - ignore error, pretend nothing happened and move on to the next StatefulSet
  1999. onStatefulSetUpdateFailureAction: rollback
  2000. ################################################
  2001. ##
  2002. ## ClickHouse Settings Section
  2003. ##
  2004. ################################################
  2005. # Default values for ClickHouse user configuration
  2006. # 1. user/profile - string
  2007. # 2. user/quota - string
  2008. # 3. user/networks/ip - multiple strings
  2009. # 4. user/password - string
  2010. chConfigUserDefaultProfile: default
  2011. chConfigUserDefaultQuota: default
  2012. chConfigUserDefaultNetworksIP:
  2013. - "::1"
  2014. - "127.0.0.1"
  2015. chConfigUserDefaultPassword: "default"
  2016. # Default host_regexp to limit network connectivity from outside
  2017. chConfigNetworksHostRegexpTemplate: "(chi-{chi}-[^.]+\\d+-\\d+|clickhouse\\-{chi})\\.{namespace}\\.svc\\.cluster\\.local$"
  2018. ################################################
  2019. ##
  2020. ## Access to ClickHouse instances
  2021. ##
  2022. ################################################
  2023. # ClickHouse credentials (username, password and port) to be used by operator to connect to ClickHouse instances
  2024. # for:
  2025. # 1. Metrics requests
  2026. # 2. Schema maintenance
  2027. # 3. DROP DNS CACHE
  2028. # User with such credentials can be specified in additional ClickHouse .xml config files,
  2029. # located in `chUsersConfigsPath` folder
  2030. chUsername: clickhouse_operator
  2031. chPassword: clickhouse_operator_password
  2032. # Location of k8s Secret with username and password to be used by operator to connect to ClickHouse instances
  2033. # Can be used instead of explicitly specified username and password
  2034. chCredentialsSecretNamespace: ""
  2035. chCredentialsSecretName: ""
  2036. # Port where to connect to ClickHouse instances to
  2037. chPort: 8123
  2038. ################################################
  2039. ##
  2040. ## Log parameters
  2041. ##
  2042. ################################################
  2043. logtostderr: "true"
  2044. alsologtostderr: "false"
  2045. v: "1"
  2046. stderrthreshold: ""
  2047. vmodule: ""
  2048. log_backtrace_at: ""
  2049. ################################################
  2050. ##
  2051. ## Runtime parameters
  2052. ##
  2053. ################################################
  2054. # Max number of concurrent reconciles in progress
  2055. reconcileThreadsNumber: 10
  2056. reconcileWaitExclude: false
  2057. reconcileWaitInclude: false
  2058. ################################################
  2059. ##
  2060. ## Labels management parameters
  2061. ##
  2062. ################################################
  2063. # When propagating labels from the chi's `metadata.labels` section to child objects' `metadata.labels`,
  2064. # exclude labels from the following list:
  2065. #excludeFromPropagationLabels:
  2066. # - "labelA"
  2067. # - "labelB"
  2068. # Whether to append *Scope* labels to StatefulSet and Pod.
  2069. # Full list of available *scope* labels check in labeler.go
  2070. # LabelShardScopeIndex
  2071. # LabelReplicaScopeIndex
  2072. # LabelCHIScopeIndex
  2073. # LabelCHIScopeCycleSize
  2074. # LabelCHIScopeCycleIndex
  2075. # LabelCHIScopeCycleOffset
  2076. # LabelClusterScopeIndex
  2077. # LabelClusterScopeCycleSize
  2078. # LabelClusterScopeCycleIndex
  2079. # LabelClusterScopeCycleOffset
  2080. appendScopeLabels: "no"
  2081. ---
  2082. # Possible Template Parameters:
  2083. #
  2084. # kube-system
  2085. # altinity/clickhouse-operator:0.15.0
  2086. # etc-clickhouse-operator-confd-files
  2087. #
  2088. apiVersion: v1
  2089. kind: ConfigMap
  2090. metadata:
  2091. name: etc-clickhouse-operator-confd-files
  2092. namespace: kube-system
  2093. labels:
  2094. app: clickhouse-operator
  2095. data:
  2096. ---
  2097. # Possible Template Parameters:
  2098. #
  2099. # kube-system
  2100. # altinity/clickhouse-operator:0.15.0
  2101. # etc-clickhouse-operator-configd-files
  2102. #
  2103. apiVersion: v1
  2104. kind: ConfigMap
  2105. metadata:
  2106. name: etc-clickhouse-operator-configd-files
  2107. namespace: kube-system
  2108. labels:
  2109. app: clickhouse-operator
  2110. data:
  2111. 01-clickhouse-01-listen.xml: |
  2112. <yandex>
  2113. <!-- Listen wildcard address to allow accepting connections from other containers and host network. -->
  2114. <listen_host>::</listen_host>
  2115. <listen_host>0.0.0.0</listen_host>
  2116. <listen_try>1</listen_try>
  2117. </yandex>
  2118. 01-clickhouse-02-logger.xml: |
  2119. <yandex>
  2120. <logger>
  2121. <!-- Possible levels: https://github.com/pocoproject/poco/blob/develop/Foundation/include/Poco/Logger.h#L105 -->
  2122. <level>debug</level>
  2123. <log>/var/log/clickhouse-server/clickhouse-server.log</log>
  2124. <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
  2125. <size>1000M</size>
  2126. <count>10</count>
  2127. <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) -->
  2128. <console>1</console>
  2129. </logger>
  2130. </yandex>
  2131. 01-clickhouse-03-query_log.xml: |
  2132. <yandex>
  2133. <query_log replace="1">
  2134. <database>system</database>
  2135. <table>query_log</table>
  2136. <engine>Engine = MergeTree PARTITION BY event_date ORDER BY event_time TTL event_date + interval 30 day</engine>
  2137. <flush_interval_milliseconds>7500</flush_interval_milliseconds>
  2138. </query_log>
  2139. <query_thread_log remove="1"/>
  2140. </yandex>
  2141. 01-clickhouse-04-part_log.xml: |
  2142. <yandex>
  2143. <part_log replace="1">
  2144. <database>system</database>
  2145. <table>part_log</table>
  2146. <engine>Engine = MergeTree PARTITION BY event_date ORDER BY event_time TTL event_date + interval 30 day</engine>
  2147. <flush_interval_milliseconds>7500</flush_interval_milliseconds>
  2148. </part_log>
  2149. </yandex>
  2150. ---
  2151. # Possible Template Parameters:
  2152. #
  2153. # kube-system
  2154. # altinity/clickhouse-operator:0.15.0
  2155. # etc-clickhouse-operator-templatesd-files
  2156. #
  2157. apiVersion: v1
  2158. kind: ConfigMap
  2159. metadata:
  2160. name: etc-clickhouse-operator-templatesd-files
  2161. namespace: kube-system
  2162. labels:
  2163. app: clickhouse-operator
  2164. data:
  2165. 001-templates.json.example: |
  2166. {
  2167. "apiVersion": "clickhouse.altinity.com/v1",
  2168. "kind": "ClickHouseInstallationTemplate",
  2169. "metadata": {
  2170. "name": "01-default-volumeclaimtemplate"
  2171. },
  2172. "spec": {
  2173. "templates": {
  2174. "volumeClaimTemplates": [
  2175. {
  2176. "name": "chi-default-volume-claim-template",
  2177. "spec": {
  2178. "accessModes": [
  2179. "ReadWriteOnce"
  2180. ],
  2181. "resources": {
  2182. "requests": {
  2183. "storage": "2Gi"
  2184. }
  2185. }
  2186. }
  2187. }
  2188. ],
  2189. "podTemplates": [
  2190. {
  2191. "name": "chi-default-oneperhost-pod-template",
  2192. "distribution": "OnePerHost",
  2193. "spec": {
  2194. "containers" : [
  2195. {
  2196. "name": "clickhouse",
  2197. "image": "yandex/clickhouse-server:19.3.7",
  2198. "ports": [
  2199. {
  2200. "name": "http",
  2201. "containerPort": 8123
  2202. },
  2203. {
  2204. "name": "client",
  2205. "containerPort": 9000
  2206. },
  2207. {
  2208. "name": "interserver",
  2209. "containerPort": 9009
  2210. }
  2211. ]
  2212. }
  2213. ]
  2214. }
  2215. }
  2216. ]
  2217. }
  2218. }
  2219. }
  2220. default-pod-template.yaml.example: |
  2221. apiVersion: "clickhouse.altinity.com/v1"
  2222. kind: "ClickHouseInstallationTemplate"
  2223. metadata:
  2224. name: "default-oneperhost-pod-template"
  2225. spec:
  2226. templates:
  2227. podTemplates:
  2228. - name: default-oneperhost-pod-template
  2229. distribution: "OnePerHost"
  2230. default-storage-template.yaml.example: |
  2231. apiVersion: "clickhouse.altinity.com/v1"
  2232. kind: "ClickHouseInstallationTemplate"
  2233. metadata:
  2234. name: "default-storage-template-2Gi"
  2235. spec:
  2236. templates:
  2237. volumeClaimTemplates:
  2238. - name: default-storage-template-2Gi
  2239. spec:
  2240. accessModes:
  2241. - ReadWriteOnce
  2242. resources:
  2243. requests:
  2244. storage: 2Gi
  2245. readme: |
  2246. Templates in this folder are packaged with an operator and available via 'useTemplate'
  2247. ---
  2248. # Possible Template Parameters:
  2249. #
  2250. # kube-system
  2251. # altinity/clickhouse-operator:0.15.0
  2252. # etc-clickhouse-operator-usersd-files
  2253. #
  2254. apiVersion: v1
  2255. kind: ConfigMap
  2256. metadata:
  2257. name: etc-clickhouse-operator-usersd-files
  2258. namespace: kube-system
  2259. labels:
  2260. app: clickhouse-operator
  2261. data:
  2262. 01-clickhouse-user.xml: |
  2263. <yandex>
  2264. <users>
  2265. <clickhouse_operator>
  2266. <networks>
  2267. <ip>127.0.0.1</ip>
  2268. <ip>0.0.0.0/0</ip>
  2269. <ip>::/0</ip>
  2270. </networks>
  2271. <password_sha256_hex>716b36073a90c6fe1d445ac1af85f4777c5b7a155cea359961826a030513e448</password_sha256_hex>
  2272. <profile>clickhouse_operator</profile>
  2273. <quota>default</quota>
  2274. </clickhouse_operator>
  2275. </users>
  2276. <profiles>
  2277. <clickhouse_operator>
  2278. <log_queries>0</log_queries>
  2279. <skip_unavailable_shards>1</skip_unavailable_shards>
  2280. <http_connection_timeout>10</http_connection_timeout>
  2281. </clickhouse_operator>
  2282. </profiles>
  2283. </yandex>
  2284. 02-clickhouse-default-profile.xml: |
  2285. <yandex>
  2286. <profiles>
  2287. <default>
  2288. <log_queries>1</log_queries>
  2289. <connect_timeout_with_failover_ms>1000</connect_timeout_with_failover_ms>
  2290. <distributed_aggregation_memory_efficient>1</distributed_aggregation_memory_efficient>
  2291. <parallel_view_processing>1</parallel_view_processing>
  2292. </default>
  2293. </profiles>
  2294. </yandex>
  2295. 03-database-ordinary.xml: |
  2296. <!-- Remove it for ClickHouse versions before 20.4 -->
  2297. <yandex>
  2298. <profiles>
  2299. <default>
  2300. <default_database_engine>Ordinary</default_database_engine>
  2301. </default>
  2302. </profiles>
  2303. </yandex>
  2304. ---
  2305. # Possible Template Parameters:
  2306. #
  2307. # kube-system
  2308. # altinity/clickhouse-operator:0.15.0
  2309. # altinity/metrics-exporter:0.15.0
  2310. #
  2311. # Setup Deployment for clickhouse-operator
  2312. # Deployment would be created in kubectl-specified namespace
  2313. kind: Deployment
  2314. apiVersion: apps/v1
  2315. metadata:
  2316. name: clickhouse-operator
  2317. namespace: kube-system
  2318. labels:
  2319. app: clickhouse-operator
  2320. spec:
  2321. replicas: 1
  2322. selector:
  2323. matchLabels:
  2324. app: clickhouse-operator
  2325. template:
  2326. metadata:
  2327. labels:
  2328. app: clickhouse-operator
  2329. annotations:
  2330. prometheus.io/port: '8888'
  2331. prometheus.io/scrape: 'true'
  2332. spec:
  2333. serviceAccountName: clickhouse-operator
  2334. volumes:
  2335. - name: etc-clickhouse-operator-folder
  2336. configMap:
  2337. name: etc-clickhouse-operator-files
  2338. - name: etc-clickhouse-operator-confd-folder
  2339. configMap:
  2340. name: etc-clickhouse-operator-confd-files
  2341. - name: etc-clickhouse-operator-configd-folder
  2342. configMap:
  2343. name: etc-clickhouse-operator-configd-files
  2344. - name: etc-clickhouse-operator-templatesd-folder
  2345. configMap:
  2346. name: etc-clickhouse-operator-templatesd-files
  2347. - name: etc-clickhouse-operator-usersd-folder
  2348. configMap:
  2349. name: etc-clickhouse-operator-usersd-files
  2350. containers:
  2351. - name: clickhouse-operator
  2352. image: altinity/clickhouse-operator:0.15.0
  2353. imagePullPolicy: Always
  2354. volumeMounts:
  2355. - name: etc-clickhouse-operator-folder
  2356. mountPath: /etc/clickhouse-operator
  2357. - name: etc-clickhouse-operator-confd-folder
  2358. mountPath: /etc/clickhouse-operator/conf.d
  2359. - name: etc-clickhouse-operator-configd-folder
  2360. mountPath: /etc/clickhouse-operator/config.d
  2361. - name: etc-clickhouse-operator-templatesd-folder
  2362. mountPath: /etc/clickhouse-operator/templates.d
  2363. - name: etc-clickhouse-operator-usersd-folder
  2364. mountPath: /etc/clickhouse-operator/users.d
  2365. env:
  2366. # Pod-specific
  2367. # spec.nodeName: ip-172-20-52-62.ec2.internal
  2368. - name: OPERATOR_POD_NODE_NAME
  2369. valueFrom:
  2370. fieldRef:
  2371. fieldPath: spec.nodeName
  2372. # metadata.name: clickhouse-operator-6f87589dbb-ftcsf
  2373. - name: OPERATOR_POD_NAME
  2374. valueFrom:
  2375. fieldRef:
  2376. fieldPath: metadata.name
  2377. # metadata.namespace: kube-system
  2378. - name: OPERATOR_POD_NAMESPACE
  2379. valueFrom:
  2380. fieldRef:
  2381. fieldPath: metadata.namespace
  2382. # status.podIP: 100.96.3.2
  2383. - name: OPERATOR_POD_IP
  2384. valueFrom:
  2385. fieldRef:
  2386. fieldPath: status.podIP
  2387. # spec.serviceAccount: clickhouse-operator
  2388. # spec.serviceAccountName: clickhouse-operator
  2389. - name: OPERATOR_POD_SERVICE_ACCOUNT
  2390. valueFrom:
  2391. fieldRef:
  2392. fieldPath: spec.serviceAccountName
  2393. # Container-specific
  2394. - name: OPERATOR_CONTAINER_CPU_REQUEST
  2395. valueFrom:
  2396. resourceFieldRef:
  2397. containerName: clickhouse-operator
  2398. resource: requests.cpu
  2399. - name: OPERATOR_CONTAINER_CPU_LIMIT
  2400. valueFrom:
  2401. resourceFieldRef:
  2402. containerName: clickhouse-operator
  2403. resource: limits.cpu
  2404. - name: OPERATOR_CONTAINER_MEM_REQUEST
  2405. valueFrom:
  2406. resourceFieldRef:
  2407. containerName: clickhouse-operator
  2408. resource: requests.memory
  2409. - name: OPERATOR_CONTAINER_MEM_LIMIT
  2410. valueFrom:
  2411. resourceFieldRef:
  2412. containerName: clickhouse-operator
  2413. resource: limits.memory
  2414. - name: metrics-exporter
  2415. image: altinity/metrics-exporter:0.15.0
  2416. imagePullPolicy: Always
  2417. volumeMounts:
  2418. - name: etc-clickhouse-operator-folder
  2419. mountPath: /etc/clickhouse-operator
  2420. - name: etc-clickhouse-operator-confd-folder
  2421. mountPath: /etc/clickhouse-operator/conf.d
  2422. - name: etc-clickhouse-operator-configd-folder
  2423. mountPath: /etc/clickhouse-operator/config.d
  2424. - name: etc-clickhouse-operator-templatesd-folder
  2425. mountPath: /etc/clickhouse-operator/templates.d
  2426. - name: etc-clickhouse-operator-usersd-folder
  2427. mountPath: /etc/clickhouse-operator/users.d
  2428. ---
  2429. # Possible Template Parameters:
  2430. #
  2431. # kube-system
  2432. #
  2433. # Setup ClusterIP Service to provide monitoring metrics for Prometheus
  2434. # Service would be created in kubectl-specified namespace
  2435. # In order to get access outside of k8s it should be exposed as:
  2436. # kubectl --namespace prometheus port-forward service/prometheus 9090
  2437. # and point browser to localhost:9090
  2438. kind: Service
  2439. apiVersion: v1
  2440. metadata:
  2441. name: clickhouse-operator-metrics
  2442. namespace: kube-system
  2443. labels:
  2444. app: clickhouse-operator
  2445. spec:
  2446. ports:
  2447. - port: 8888
  2448. name: clickhouse-operator-metrics
  2449. selector:
  2450. app: clickhouse-operator

源文件来自于https://raw.githubusercontent.com/Altinity/clickhouse-operator/master/deploy/operator/clickhouse-operator-install.yaml

我把其中的命名空间kube-system换成了ckk8s,因为在要部署的集群上已经有了kube-system命名空间!

2)部署

  1. kubectl apply -f clickhouse-operator-install.yaml -n ckk8s
  2. 输出为:
  3. customresourcedefinition.apiextensions.k8s.io/clickhouseinstallations.clickhouse.altinity.com configured
  4. customresourcedefinition.apiextensions.k8s.io/clickhouseinstallationtemplates.clickhouse.altinity.com configured
  5. customresourcedefinition.apiextensions.k8s.io/clickhouseoperatorconfigurations.clickhouse.altinity.com configured
  6. serviceaccount/clickhouse-operator created
  7. clusterrole.rbac.authorization.k8s.io/clickhouse-operator-ckk8s created
  8. clusterrolebinding.rbac.authorization.k8s.io/clickhouse-operator-ckk8s created
  9. configmap/etc-clickhouse-operator-files created
  10. configmap/etc-clickhouse-operator-confd-files created
  11. configmap/etc-clickhouse-operator-configd-files created
  12. configmap/etc-clickhouse-operator-templatesd-files created
  13. configmap/etc-clickhouse-operator-usersd-files created
  14. deployment.apps/clickhouse-operator created
  15. service/clickhouse-operator-metrics created

3)查看

  1. kubectl get pod -n ckk8s
  2. 输出:
  3. clickhouse-operator-7944c8f9c-qcvvd 2/2 Running 0 109s

2、配置zookeeper

1)创建zookeeper-3-node.yaml文件

vim zookeeper-3-node.yaml

yaml内容为:

  1. # Setup Service to provide access to Zookeeper for clients
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. # DNS would be like zookeeper.zoons
  6. name: zookeeper
  7. labels:
  8. app: zookeeper
  9. spec:
  10. ports:
  11. - port: 2181
  12. name: client
  13. - port: 7000
  14. name: prometheus
  15. selector:
  16. app: zookeeper
  17. what: node
  18. ---
  19. # Setup Headless Service for StatefulSet
  20. apiVersion: v1
  21. kind: Service
  22. metadata:
  23. # DNS would be like zookeeper-0.zookeepers.etc
  24. name: zookeepers
  25. labels:
  26. app: zookeeper
  27. spec:
  28. ports:
  29. - port: 2888
  30. name: server
  31. - port: 3888
  32. name: leader-election
  33. clusterIP: None
  34. selector:
  35. app: zookeeper
  36. what: node
  37. ---
  38. # Setup max number of unavailable pods in StatefulSet
  39. apiVersion: policy/v1beta1
  40. kind: PodDisruptionBudget
  41. metadata:
  42. name: zookeeper-pod-disruption-budget
  43. spec:
  44. selector:
  45. matchLabels:
  46. app: zookeeper
  47. maxUnavailable: 1
  48. ---
  49. # Setup Zookeeper StatefulSet
  50. # Possible params:
  51. # 1. replicas
  52. # 2. memory
  53. # 3. cpu
  54. # 4. storage
  55. # 5. storageClassName
  56. # 6. user to run app
  57. apiVersion: apps/v1
  58. kind: StatefulSet
  59. metadata:
  60. # nodes would be named as zookeeper-0, zookeeper-1, zookeeper-2
  61. name: zookeeper
  62. spec:
  63. selector:
  64. matchLabels:
  65. app: zookeeper
  66. serviceName: zookeepers
  67. replicas: 3
  68. updateStrategy:
  69. type: RollingUpdate
  70. podManagementPolicy: Parallel
  71. template:
  72. metadata:
  73. labels:
  74. app: zookeeper
  75. what: node
  76. annotations:
  77. prometheus.io/port: '7000'
  78. prometheus.io/scrape: 'true'
  79. spec:
  80. affinity:
  81. podAntiAffinity:
  82. requiredDuringSchedulingIgnoredDuringExecution:
  83. - labelSelector:
  84. matchExpressions:
  85. - key: "app"
  86. operator: In
  87. values:
  88. - zookeeper
  89. topologyKey: "kubernetes.io/hostname"
  90. containers:
  91. - name: kubernetes-zookeeper
  92. imagePullPolicy: IfNotPresent
  93. image: "docker.io/zookeeper:3.6.3"
  94. resources:
  95. requests:
  96. memory: "512M"
  97. cpu: "1"
  98. limits:
  99. memory: "4Gi"
  100. cpu: "2"
  101. ports:
  102. - containerPort: 2181
  103. name: client
  104. - containerPort: 2888
  105. name: server
  106. - containerPort: 3888
  107. name: leader-election
  108. - containerPort: 7000
  109. name: prometheus
  110. # See those links for proper startup settings:
  111. # https://github.com/kow3ns/kubernetes-zookeeper/blob/master/docker/scripts/start-zookeeper
  112. # https://clickhouse.yandex/docs/en/operations/tips/#zookeeper
  113. # https://github.com/ClickHouse/ClickHouse/issues/11781
  114. command:
  115. - bash
  116. - -x
  117. - -c
  118. - |
  119. SERVERS=3 &&
  120. HOST=`hostname -s` &&
  121. DOMAIN=`hostname -d` &&
  122. CLIENT_PORT=2181 &&
  123. SERVER_PORT=2888 &&
  124. ELECTION_PORT=3888 &&
  125. PROMETHEUS_PORT=7000 &&
  126. ZOO_DATA_DIR=/var/lib/zookeeper/data &&
  127. ZOO_DATA_LOG_DIR=/var/lib/zookeeper/datalog &&
  128. {
  129. echo "clientPort=${CLIENT_PORT}"
  130. echo 'tickTime=2000'
  131. echo 'initLimit=300'
  132. echo 'syncLimit=10'
  133. echo 'maxClientCnxns=2000'
  134. echo 'maxSessionTimeout=60000000'
  135. echo "dataDir=${ZOO_DATA_DIR}"
  136. echo "dataLogDir=${ZOO_DATA_LOG_DIR}"
  137. echo 'autopurge.snapRetainCount=10'
  138. echo 'autopurge.purgeInterval=1'
  139. echo 'preAllocSize=131072'
  140. echo 'snapCount=3000000'
  141. echo 'leaderServes=yes'
  142. echo 'standaloneEnabled=false'
  143. echo '4lw.commands.whitelist=*'
  144. echo 'metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider'
  145. echo "metricsProvider.httpPort=${PROMETHEUS_PORT}"
  146. } > /conf/zoo.cfg &&
  147. {
  148. echo "zookeeper.root.logger=CONSOLE"
  149. echo "zookeeper.console.threshold=INFO"
  150. echo "log4j.rootLogger=\${zookeeper.root.logger}"
  151. echo "log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender"
  152. echo "log4j.appender.CONSOLE.Threshold=\${zookeeper.console.threshold}"
  153. echo "log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout"
  154. echo "log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n"
  155. } > /conf/log4j.properties &&
  156. echo 'JVMFLAGS="-Xms128M -Xmx4G -XX:+UseG1GC -XX:+CMSParallelRemarkEnabled"' > /conf/java.env &&
  157. if [[ $HOST =~ (.*)-([0-9]+)$ ]]; then
  158. NAME=${BASH_REMATCH[1]}
  159. ORD=${BASH_REMATCH[2]}
  160. else
  161. echo "Failed to parse name and ordinal of Pod"
  162. exit 1
  163. fi &&
  164. mkdir -p ${ZOO_DATA_DIR} &&
  165. mkdir -p ${ZOO_DATA_LOG_DIR} &&
  166. export MY_ID=$((ORD+1)) &&
  167. echo $MY_ID > $ZOO_DATA_DIR/myid &&
  168. for (( i=1; i<=$SERVERS; i++ )); do
  169. echo "server.$i=$NAME-$((i-1)).$DOMAIN:$SERVER_PORT:$ELECTION_PORT" >> /conf/zoo.cfg;
  170. done &&
  171. chown -Rv zookeeper "$ZOO_DATA_DIR" "$ZOO_DATA_LOG_DIR" "$ZOO_LOG_DIR" "$ZOO_CONF_DIR" &&
  172. zkServer.sh start-foreground
  173. readinessProbe:
  174. exec:
  175. command:
  176. - bash
  177. - -c
  178. - "OK=$(echo ruok | nc 127.0.0.1 2181); if [[ \"$OK\" == \"imok\" ]]; then exit 0; else exit 1; fi"
  179. initialDelaySeconds: 10
  180. timeoutSeconds: 5
  181. livenessProbe:
  182. exec:
  183. command:
  184. - bash
  185. - -c
  186. - "OK=$(echo ruok | nc 127.0.0.1 2181); if [[ \"$OK\" == \"imok\" ]]; then exit 0; else exit 1; fi"
  187. initialDelaySeconds: 10
  188. timeoutSeconds: 5
  189. volumeMounts:
  190. - name: datadir-volume
  191. mountPath: /var/lib/zookeeper
  192. # Run as a non-privileged user
  193. securityContext:
  194. runAsUser: 1000
  195. fsGroup: 1000
  196. volumeClaimTemplates:
  197. - metadata:
  198. name: datadir-volume
  199. spec:
  200. accessModes:
  201. - ReadWriteOnce
  202. resources:
  203. requests:
  204. storage: 25Gi

2)部署zookeeper

  1. kubectl apply -f zookeeper-3-node.yaml -n ckk8s
  2. 输出:
  3. service/zookeeper created
  4. service/zookeepers created
  5. poddisruptionbudget.policy/zookeeper-pod-disruption-budget created
  6. statefulset.apps/zookeeper created

3)查看zookeeper集群

查看集群中所有pod

  1. kubectl get pod -n ckk8s
  2. 输出为:
  3. NAME READY STATUS RESTARTS AGE
  4. zookeeper-0 1/1 Running 0 2m29s
  5. zookeeper-1 1/1 Running 0 2m29s
  6. zookeeper-2 1/1 Running 0 2m28s

查看服务

  1. kubectl get service -n ckk8s
  2. 输出
  3. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  4. zookeeper ClusterIP 10.96.93.181 <none> 2181/TCP,7000/TCP 2m46s
  5. zookeepers ClusterIP None <none> 2888/TCP,3888/TCP 2m46s

查看statefulsets

  1. kubectl get statefulset -n ckk8s
  2. 输出
  3. NAME READY AGE
  4. zookeeper 3/3 4m34s

此时zookeeper集群正常启动,且在运行

3、一个示例

3.1部署1分片1副本集群

1)部署1分片1副本

创建文件sample-1shard-1replica.yaml

yaml内容为:

  1. apiVersion: "clickhouse.altinity.com/v1"
  2. kind: "ClickHouseInstallation"
  3. metadata:
  4. name: "sample-01"
  5. spec:
  6. configuration:
  7. clusters:
  8. - name: "cluster1"
  9. layout:
  10. shardsCount: 1
  11. replicasCount: 1

部署

  1. kubectl apply -f sample-1shard-1replica.yaml
  2. 输出:
  3. clickhouseinstallation.clickhouse.altinity.com/sample-01 created

2)查看pod是否运行

  1. kubectl get pod -n ckk8s
  2. 输出:
  3. NAME READY STATUS RESTARTS AGE
  4. chi-sample-01-cluster1-0-0-0 1/1 Running 0 85s

3)查看服务

  1. kubectl get service -n ckk8s
  2. 输出:
  3. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  4. chi-simple-01-cluster-0-0 ClusterIP None <none> 8123/TCP,9000/TCP,9009/TCP 67s
  5. clickhouse-simple-01 LoadBalancer 10.104.76.159 <pending> 8123:30890/TCP,9000:32659/TCP 69s

4)连接clickhouse数据库

第一种方式:使用clickhouse-client访问集群

默认的用户名和密码在clickhouse-operator-install.yaml文件设置,可以自行修改,默认的值为:

  1. chUsername: clickhouse_operator
  2. chPassword:clickhouse_operator_password
  3. ///见clickhouse-operator-install.yaml文件第2048-2049

此时访问方式如下:

clickhouse-client --host hostname --user=clickhouse_operator --password=clickhouse_operator_password

hostname的值为第三步clickhouse-sample-01对应的external-ip的值,但此处为<pending>所以暂时无法通过这种方式访问

第二种方式:使用kubcetl exec -it访问,后面接的是pod的name

  1. kubectl -n ckk8s exec -it chi-sample-01-cluster1-0-0-0 -- clickhouse-client
  2. 输出为:
  3. ClickHouse client version 21.8.5.7 (official build).
  4. Connecting to localhost:9000 as user default.
  5. Connected to ClickHouse server version 21.8.5 revision 54449.
  6. chi-simple-01-cluster-0-0-0.chi-simple-01-cluster-0-0.ckk8s.svc.cluster.local :)

查看集群名字

  1. select * from system.clusters
  2. ┌─cluster──────────────────────────────────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name──────────────────┬─host_address─┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─slowdowns_count─┬─estimated_recovery_time─┐
  3. │ all-replicated │ 111 │ chi-sample-01-cluster1-0-0127.0.0.190001default │ │ 000
  4. │ all-sharded │ 111 │ chi-sample-01-cluster1-0-0127.0.0.190001default │ │ 000
  5. │ cluster1111 │ chi-sample-01-cluster1-0-0127.0.0.190001default │ │ 000
  6. test_cluster_two_shards │ 111127.0.0.1127.0.0.190001default │ │ 000
  7. test_cluster_two_shards │ 211127.0.0.2127.0.0.290000default │ │ 000
  8. test_cluster_two_shards_internal_replication │ 111127.0.0.1127.0.0.190001default │ │ 000
  9. test_cluster_two_shards_internal_replication │ 211127.0.0.2127.0.0.290000default │ │ 000
  10. test_cluster_two_shards_localhost │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  11. test_cluster_two_shards_localhost │ 211 │ localhost │ 127.0.0.190001default │ │ 000
  12. test_shard_localhost │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  13. test_shard_localhost_secure │ 111 │ localhost │ 127.0.0.194400default │ │ 000
  14. test_unavailable_shard │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  15. test_unavailable_shard │ 211 │ localhost │ 127.0.0.110default │ │ 000
  16. └──────────────────────────────────────────────┴───────────┴──────────────┴─────────────┴────────────────────────────┴──────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────┴─────────────────────────┘

此时可以正常使用

3.2将该集群升级为2分片

1)创建sample-2shard_1replica.yaml文件

内容如下:

  1. apiVersion: "clickhouse.altinity.com/v1"
  2. kind: "ClickHouseInstallation"
  3. metadata:
  4. name: "sample-01"
  5. spec:
  6. configuration:
  7. clusters:
  8. - name: "cluster1"
  9. layout:
  10. shardsCount: 2
  11. replicasCount: 1

只需要修改shardCount的数量

2)部署

  1. kubectl apply -f sample-2shard_1replica.yaml -n ckk8s
  2. clickhouseinstallation.clickhouse.altinity.com/sample-01 configured

3)查看pod

  1. kubectl get pod -n ckk8s
  2. NAME READY STATUS RESTARTS AGE
  3. chi-sample-01-cluster1-0-0-0 1/1 Running 0 21m
  4. chi-sample-01-cluster1-1-0-0 1/1 Running 0 36s

从时间上可以发现第二个是新建的

4)查看service

  1. kubectl get service -n ckk8s
  2. NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. chi-sample-01-cluster1-0-0 ClusterIP None <none> 8123/TCP,9000/TCP,9009/TCP 22m
  4. chi-sample-01-cluster1-1-0 ClusterIP None <none> 8123/TCP,9000/TCP,9009/TCP 61s
  5. clickhouse-sample-01 LoadBalancer 10.96.69.232 <pending> 8123:32766/TCP,9000:30993/TCP 22m

从时间上可以发现chi-sample-01-cluster1-1-0为61s,是新建的

5)连接clickhouse数据库

  1. kubectl -n ckk8s exec -it chi-sample-01-cluster1-0-0-0 -- clickhouse-client
  2. kubectl -n ckk8s exec -it chi-sample-01-cluster1-1-0-0 -- clickhouse-client

6)查看集群

2个节点上的查看结果如下

  1. select * from system.clusters
  2. ┌─cluster──────────────────────────────────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name──────────────────┬─host_address─┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─slowdowns_count─┬─estimated_recovery_time─┐
  3. │ all-replicated │ 111 │ chi-sample-01-cluster1-0-0127.0.0.190001default │ │ 000
  4. │ all-replicated │ 112 │ chi-sample-01-cluster1-1-010.217.8.2790000default │ │ 000
  5. │ all-sharded │ 111 │ chi-sample-01-cluster1-0-0127.0.0.190001default │ │ 000
  6. │ all-sharded │ 211 │ chi-sample-01-cluster1-1-010.217.8.2790000default │ │ 000
  7. │ cluster1111 │ chi-sample-01-cluster1-0-0127.0.0.190001default │ │ 000
  8. │ cluster1211 │ chi-sample-01-cluster1-1-010.217.8.2790000default │ │ 000
  9. test_cluster_two_shards │ 111127.0.0.1127.0.0.190001default │ │ 000
  10. test_cluster_two_shards │ 211127.0.0.2127.0.0.290000default │ │ 000
  11. test_cluster_two_shards_internal_replication │ 111127.0.0.1127.0.0.190001default │ │ 000
  12. test_cluster_two_shards_internal_replication │ 211127.0.0.2127.0.0.290000default │ │ 000
  13. test_cluster_two_shards_localhost │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  14. test_cluster_two_shards_localhost │ 211 │ localhost │ 127.0.0.190001default │ │ 000
  15. test_shard_localhost │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  16. test_shard_localhost_secure │ 111 │ localhost │ 127.0.0.194400default │ │ 000
  17. test_unavailable_shard │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  18. test_unavailable_shard │ 211 │ localhost │ 127.0.0.110default │ │ 000
  19. └──────────────────────────────────────────────┴───────────┴──────────────┴─────────────┴────────────────────────────┴──────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────┴─────────────────────────┘

为什么2个cluster1??????

3.3进入pod

  1. kubectl -n ckk8s exec -it chi-sample-01-cluster1-1-0-0 -- bash
  2. root@chi-sample-01-cluster1-1-0-0:/# ls
  3. bin boot dev docker-entrypoint-initdb.d entrypoint.sh etc home lib lib32 lib64 libx32 media mnt opt proc root run sbin srv sys tmp usr var

其实就是进入了clickhouse-server容器

1)查看默认服务端配置文件

  1. cd /etc/clickhouse-server
  2. root@chi-sample-01-cluster1-1-0-0:/# cd /etc/clickhouse-server
  3. root@chi-sample-01-cluster1-1-0-0:/etc/clickhouse-server# ls
  4. conf.d config.d config.xml users.d users.xml

2)查看默认数据存储目录

  1. root@chi-sample-01-cluster1-1-0-0:/var/log/clickhouse-server# cd /var/lib/clickhouse
  2. root@chi-sample-01-cluster1-1-0-0:/var/lib/clickhouse# ls
  3. access data dictionaries_lib flags format_schemas metadata metadata_dropped preprocessed_configs status store tmp user_files
  4. root@chi-sample-01-cluster1-1-0-0:/var/lib/clickhouse#

3)查看默认日志目录

  1. root@chi-sample-01-cluster1-1-0-0:/etc/clickhouse-server# cd /var/log/clickhouse-server
  2. root@chi-sample-01-cluster1-1-0-0:/var/log/clickhouse-server# ls
  3. clickhouse-server.err.log clickhouse-server.log

4)查看配置文件中的分片和副本信息

打开config.d下的chop-generated-remote_servers.xml

  1. root@chi-sample-01-cluster1-0-0-0:/etc/clickhouse-server/config.d# cat chop-generated-remote_servers.xml
  2. <yandex>
  3. <remote_servers>
  4. <!-- User-specified clusters -->
  5. <cluster1>
  6. <shard>
  7. <internal_replication>false</internal_replication>
  8. <replica>
  9. <host>chi-sample-01-cluster1-0-0</host>
  10. <port>9000</port>
  11. </replica>
  12. </shard>
  13. <shard>
  14. <internal_replication>false</internal_replication>
  15. <replica>
  16. <host>chi-sample-01-cluster1-1-0</host>
  17. <port>9000</port>
  18. </replica>
  19. </shard>
  20. </cluster1>
  21. <!-- Autogenerated clusters -->
  22. <all-replicated>
  23. <shard>
  24. <internal_replication>true</internal_replication>
  25. <replica>
  26. <host>chi-sample-01-cluster1-0-0</host>
  27. <port>9000</port>
  28. </replica>
  29. <replica>
  30. <host>chi-sample-01-cluster1-1-0</host>
  31. <port>9000</port>
  32. </replica>
  33. </shard>
  34. </all-replicated>
  35. <all-sharded>
  36. <shard>
  37. <internal_replication>false</internal_replication>
  38. <replica>
  39. <host>chi-sample-01-cluster1-0-0</host>
  40. <port>9000</port>
  41. </replica>
  42. </shard>
  43. <shard>
  44. <internal_replication>false</internal_replication>
  45. <replica>
  46. <host>chi-sample-01-cluster1-1-0</host>
  47. <port>9000</port>
  48. </replica>
  49. </shard>
  50. </all-sharded>
  51. </remote_servers>
  52. </yandex>

可以发现此处的配置文件指给出了分片和副本的信息

4、zookeeper和副本

4.1使用zookeeper

     第3部分的示例中还没有使用到zookeeper,clickhouse-operator不提供zookeeper,zookeeper必须外部安装。第2部分我们已经安装了zookeeper

1)创建sample-2shard-2replica.yaml文件,内容如下

  1. apiVersion: "clickhouse.altinity.com/v1"
  2. kind: "ClickHouseInstallation"
  3. metadata:
  4. name: "sample-01"
  5. spec:
  6. configuration:
  7. zookeeper:
  8. nodes:
  9. - host: zookeeper.ckk8s
  10. port: 2181
  11. clusters:
  12. - name: "cluster1"
  13. layout:
  14. shardsCount: 2
  15. replicasCount: 2

2)部署

  1. kubectl apply -f sample-2shard-2replica.yaml -n ckk8s
  2. clickhouseinstallation.clickhouse.altinity.com/sample-01 configured

3)查看pod

  1. kubectl get pod -n ckk8s
  2. NAME READY STATUS RESTARTS AGE
  3. chi-sample-01-cluster1-0-0-0 1/1 Running 0 2m24s
  4. chi-sample-01-cluster1-0-1-0 0/1 ContainerCreating 0 2s
  5. chi-sample-01-cluster1-1-0-0 1/1 Running 0 5m10s

发现新的副本正在创建

4) 连接clickhouse数据库

  1. kubectl -n ckk8s exec -it chi-sample-01-cluster1-0-1-0 -- clickhouse-client
  2. ClickHouse client version 21.8.5.7 (official build).
  3. Connecting to localhost:9000 as user default.
  4. Connected to ClickHouse server version 21.8.5 revision 54449.

5)查看集群

  1. select * from system.clusters;
  2. cluster──────────────────────────────────────┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_name──────────────────┬─host_address─┬─port─┬─is_local─┬─user────┬─default_database─┬─errors_count─┬─slowdowns_count─┬─estimated_recovery_time─┐
  3. │ all-replicated │ 111 │ chi-sample-01-cluster1-0-010.217.3.19390000default │ │ 000
  4. │ all-replicated │ 112 │ chi-sample-01-cluster1-0-1127.0.0.190001default │ │ 000
  5. │ all-replicated │ 113 │ chi-sample-01-cluster1-1-010.217.3.14090000default │ │ 000
  6. │ all-replicated │ 114 │ chi-sample-01-cluster1-1-110.217.3.12390000default │ │ 000
  7. │ all-sharded │ 111 │ chi-sample-01-cluster1-0-010.217.3.19390000default │ │ 000
  8. │ all-sharded │ 211 │ chi-sample-01-cluster1-0-1127.0.0.190001default │ │ 000
  9. │ all-sharded │ 311 │ chi-sample-01-cluster1-1-010.217.3.14090000default │ │ 000
  10. │ all-sharded │ 411 │ chi-sample-01-cluster1-1-110.217.3.12390000default │ │ 000
  11. │ cluster1111 │ chi-sample-01-cluster1-0-010.217.3.19390000default │ │ 000
  12. │ cluster1112 │ chi-sample-01-cluster1-0-1127.0.0.190001default │ │ 000
  13. │ cluster1211 │ chi-sample-01-cluster1-1-010.217.3.14090000default │ │ 000
  14. │ cluster1212 │ chi-sample-01-cluster1-1-110.217.3.12390000default │ │ 000
  15. test_cluster_two_shards │ 111127.0.0.1127.0.0.190001default │ │ 000
  16. test_cluster_two_shards │ 211127.0.0.2127.0.0.290000default │ │ 000
  17. test_cluster_two_shards_internal_replication │ 111127.0.0.1127.0.0.190001default │ │ 000
  18. test_cluster_two_shards_internal_replication │ 211127.0.0.2127.0.0.290000default │ │ 000
  19. test_cluster_two_shards_localhost │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  20. test_cluster_two_shards_localhost │ 211 │ localhost │ 127.0.0.190001default │ │ 000
  21. test_shard_localhost │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  22. test_shard_localhost_secure │ 111 │ localhost │ 127.0.0.194400default │ │ 000
  23. test_unavailable_shard │ 111 │ localhost │ 127.0.0.190001default │ │ 000
  24. test_unavailable_shard │ 211 │ localhost │ 127.0.0.110default │ │ 000
  25. └──────────────────────────────────────────────┴───────────┴──────────────┴─────────────┴────────────────────────────┴──────────────┴──────┴──────────┴─────────┴──────────────────┴──────────────┴─────────────────┴─────────────────────────┘

4.2进入pod查看分片和副本、zookeeper信息

再次进入3.3部分的同一个pod

kubectl -n ckk8s exec -it chi-sample-01-cluster1-1-0-0 -- bash

1)查看分片和副本

  1. ///打开/etc/clickhouse-server/config.d/chop-generated-remote_servers.xml
  2. root@chi-sample-01-cluster1-0-0-0:/etc/clickhouse-server/config.d# cat chop-generated-remote_servers.xml
  3. <yandex>
  4. <remote_servers>
  5. <!-- User-specified clusters -->
  6. <cluster1>
  7. <shard>
  8. <internal_replication>true</internal_replication>
  9. <replica>
  10. <host>chi-sample-01-cluster1-0-0</host>
  11. <port>9000</port>
  12. </replica>
  13. <replica>
  14. <host>chi-sample-01-cluster1-0-1</host>
  15. <port>9000</port>
  16. </replica>
  17. </shard>
  18. <shard>
  19. <internal_replication>true</internal_replication>
  20. <replica>
  21. <host>chi-sample-01-cluster1-1-0</host>
  22. <port>9000</port>
  23. </replica>
  24. <replica>
  25. <host>chi-sample-01-cluster1-1-1</host>
  26. <port>9000</port>
  27. </replica>
  28. </shard>
  29. </cluster1>
  30. <!-- Autogenerated clusters -->
  31. <all-replicated>
  32. <shard>
  33. <internal_replication>true</internal_replication>
  34. <replica>
  35. <host>chi-sample-01-cluster1-0-0</host>
  36. <port>9000</port>
  37. </replica>
  38. <replica>
  39. <host>chi-sample-01-cluster1-0-1</host>
  40. <port>9000</port>
  41. </replica>
  42. <replica>
  43. <host>chi-sample-01-cluster1-1-0</host>
  44. <port>9000</port>
  45. </replica>
  46. <replica>
  47. <host>chi-sample-01-cluster1-1-1</host>
  48. <port>9000</port>
  49. </replica>
  50. </shard>
  51. </all-replicated>
  52. <all-sharded>
  53. <shard>
  54. <internal_replication>false</internal_replication>
  55. <replica>
  56. <host>chi-sample-01-cluster1-0-0</host>
  57. <port>9000</port>
  58. </replica>
  59. </shard>
  60. <shard>
  61. <internal_replication>false</internal_replication>
  62. <replica>
  63. <host>chi-sample-01-cluster1-0-1</host>
  64. <port>9000</port>
  65. </replica>
  66. </shard>
  67. <shard>
  68. <internal_replication>false</internal_replication>
  69. <replica>
  70. <host>chi-sample-01-cluster1-1-0</host>
  71. <port>9000</port>
  72. </replica>
  73. </shard>
  74. <shard>
  75. <internal_replication>false</internal_replication>
  76. <replica>
  77. <host>chi-sample-01-cluster1-1-1</host>
  78. <port>9000</port>
  79. </replica>
  80. </shard>
  81. </all-sharded>
  82. </remote_servers>
  83. </yandex>

和3.3相比增加了分片和副本的信息,因为此处是2分片2副本

2)查看marcos和zookeeper

  1. 打开/etc/clickhouse-server/conf.d/
  2. root@chi-sample-01-cluster1-0-0-0:/etc/clickhouse-server/conf.d# ls
  3. chop-generated-macros.xml chop-generated-zookeeper.xml
  4. root@chi-sample-01-cluster1-0-0-0:/etc/clickhouse-server/conf.d# cat chop-generated-macros.xml
  5. <yandex>
  6. <macros>
  7. <installation>sample-01</installation>
  8. <all-sharded-shard>0</all-sharded-shard>
  9. <cluster>cluster1</cluster>
  10. <shard>0</shard>
  11. <replica>chi-sample-01-cluster1-0-0</replica>
  12. </macros>
  13. </yandex>
  14. root@chi-sample-01-cluster1-0-0-0:/etc/clickhouse-server/conf.d# cat chop-generated-zookeeper.xml
  15. <yandex>
  16. <zookeeper>
  17. <node>
  18. <host>zookeeper.ckk8s</host>
  19. <port>2181</port>
  20. </node>
  21. </zookeeper>
  22. <distributed_ddl>
  23. <path>/clickhouse/sample-01/task_queue/ddl</path>
  24. </distributed_ddl>
  25. </yandex>

3)使用3个节点的写法

如果在sample-2shard_2replica.yaml文件中zookeeper的写法如下:

即详细指出每一个zookeeper节点

  1. zookeeper:
  2. nodes:
  3. - host: zookeeper-0.zookeepers.ckk8s
  4. port: 2181
  5. - host: zookeeper-1.zookeepers.ckk8s
  6. port: 2181
  7. - host: zookeeper-2.zookeepers.ckk8s
  8. port: 2181

则/etc/clickhouse-server/conf.d/chop-generated-zookeeper.xml文件内的zookeeper信息为

  1. <yandex>
  2. <zookeeper>
  3. <node>
  4. <host>zookeeper-0.zookeepers.ckk8s</host>
  5. <port>2181</port>
  6. </node>
  7. <node>
  8. <host>zookeeper-1.zookeepers.ckk8s</host>
  9. <port>2181</port>
  10. </node>
  11. <node>
  12. <host>zookeeper-2.zookeepers.ckk8s</host>
  13. <port>2181</port>
  14. </node>
  15. </zookeeper>
  16. <distributed_ddl>
  17. <path>/clickhouse/demo-01/task_queue/ddl</path>
  18. </distributed_ddl>
  19. </yandex>

5、创建分布式表

1)创建分布式表

  1. CREATE TABLE test AS system.one ENGINE = Distributed('cluster1', 'system', 'one')
  2. CREATE TABLE test AS system.one
  3. ENGINE = Distributed('cluster1', 'system', 'one')
  4. Query id: eab6dddb-3463-466f-aa8d-5d0cd3cea110
  5. Ok.
  6. 0 rows in set. Elapsed: 0.006 sec.

2)查询数据

  1. select * from test
  2. SELECT *
  3. FROM test
  4. Query id: 84a829f1-3ec7-424f-b1c5-44ca38a751b2
  5. ┌─dummy─┐
  6. 0
  7. └───────┘
  8. ┌─dummy─┐
  9. 0
  10. └───────┘
  11. 2 rows in set. Elapsed: 0.027 sec.

此时没有返回任何数据

3)查看哪些分片返回了数据

使用hostname()

  1. 第一次
  2. select hostName() from test;
  3. SELECT hostName()
  4. FROM test
  5. Query id: 3d5efc14-7b56-4142-a9c6-b3eee8693599
  6. ┌─hostName()───────────────────┐
  7. │ chi-sample-01-cluster1-0-1-0
  8. └──────────────────────────────┘
  9. ┌─hostName()───────────────────┐
  10. │ chi-sample-01-cluster1-1-0-0
  11. └──────────────────────────────┘
  12. 2 rows in set. Elapsed: 0.012 sec.
  13. /2
  14. select hostName() from test;
  15. SELECT hostName()
  16. FROM test
  17. Query id: 4e51ca0e-d4d8-47d5-9976-8271284a079a
  18. ┌─hostName()───────────────────┐
  19. │ chi-sample-01-cluster1-0-1-0
  20. └──────────────────────────────┘
  21. ┌─hostName()───────────────────┐
  22. │ chi-sample-01-cluster1-1-0-0
  23. └──────────────────────────────┘
  24. 2 rows in set. Elapsed: 0.007 sec.
  25. ///3
  26. select hostName() from test;
  27. SELECT hostName()
  28. FROM test
  29. Query id: b1cf71bd-a38f-4657-8323-8f868a21548b
  30. ┌─hostName()───────────────────┐
  31. │ chi-sample-01-cluster1-0-1-0
  32. └──────────────────────────────┘
  33. ┌─hostName()───────────────────┐
  34. │ chi-sample-01-cluster1-1-1-0
  35. └──────────────────────────────┘
  36. 2 rows in set. Elapsed: 0.007 sec.

运行了3次select,可以看到返回数据的分片。

问题在于:截止到目前的做法还没有持久存储。如果集群停止运行,所有的数据都会消失。

6、持久存储

     本部分介绍如何在k8s上的clickhouse集群添加持久存储。

1)创建sample-storage.yaml文件,内容如下:

  1. apiVersion: "clickhouse.altinity.com/v1"
  2. kind: "ClickHouseInstallation"
  3. metadata:
  4. name: "sample-01"
  5. spec:
  6. defaults:
  7. deployment:
  8. podTemplate: clickhouse-stable
  9. volumeClaimTemplate: storage-vc-template
  10. templates:
  11. podTemplates:
  12. - name: clickhouse-stable
  13. containers:
  14. - name: clickhouse
  15. image: yandex/clickhouse-server:latest
  16. volumeClaimTemplates:
  17. - name: storage-vc-template
  18. persistentVolumeClaim:
  19. metadata:
  20. name: storage-demo
  21. spec:
  22. storageClassName: standard
  23. accessModes:
  24. - ReadWriteOnce
  25. resources:
  26. requests:
  27. storage: 1Gi
  28. configuration:
  29. zookeeper:
  30. nodes:
  31. - host: zookeeper.ckk8s
  32. port: 2181
  33. clusters:
  34. - name: "cluster1"
  35. layout:
  36. shardsCount: 2
  37. replicasCount: 2

其中:

2)部署

  1. kubectl -n ckk8s apply -f sample-storage.yaml
  2. clickhouseinstallation.clickhouse.altinity.com/sample-01 configured

3)查看pod

  1. kubectl get pod -n ckk8s
  2. NAME READY STATUS RESTARTS AGE
  3. chi-sample-01-cluster1-0-0-0 1/1 Running 0 58m
  4. chi-sample-01-cluster1-0-1-0 1/1 Running 0 56m
  5. chi-sample-01-cluster1-1-0-0 1/1 Running 0 56m
  6. chi-sample-01-cluster1-1-1-0 1/1 Running 0 56m

4)进入pod,测试持久存储

kubectl -n ckk8s exec -it chi-sample-01-cluster1-0-0-0 /bin/bash

建表

  1. CREATE TABLE events_local on cluster '{cluster}' (
  2. event_date Date,
  3. event_type Int32,
  4. article_id Int32,
  5. title String
  6. ) engine=ReplicatedMergeTree('/clickhouse/{installation}/{cluster}/tables/{shard}/{database}/{table}', '{replica}')
  7. PARTITION BY toYYYYMM(event_date)
  8. ORDER BY (event_type, article_id);
  9. CREATE TABLE events_local ON CLUSTER `{cluster}`
  10. (
  11. `event_date` Date,
  12. `event_type` Int32,
  13. `article_id` Int32,
  14. `title` String
  15. )
  16. ENGINE = ReplicatedMergeTree('/clickhouse/{installation}/{cluster}/tables/{shard}/{database}/{table}', '{replica}')
  17. PARTITION BY toYYYYMM(event_date)
  18. ORDER BY (event_type, article_id)
  19. Query id: 7bbbf3e1-a49a-4fa0-a045-4033a1e6a918
  20. ┌─host───────────────────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
  21. │ chi-sample-01-cluster1-0-090000 │ │ 32
  22. │ chi-sample-01-cluster1-1-190000 │ │ 22
  23. └────────────────────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
  24. ┌─host───────────────────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
  25. │ chi-sample-01-cluster1-1-090000 │ │ 10
  26. │ chi-sample-01-cluster1-0-190000 │ │ 00
  27. └────────────────────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
  28. 4 rows in set. Elapsed: 0.381 sec.

创建分布式表

  1. CREATE TABLE events on cluster '{cluster}' AS events_local
  2. ENGINE = Distributed('{cluster}', default, events_local, rand());
  3. CREATE TABLE events ON CLUSTER `{cluster}` AS events_local
  4. ENGINE = Distributed('{cluster}', default, events_local, rand())
  5. Query id: 81808a54-02ae-4b6f-8edb-9049d0283ac7
  6. ┌─host───────────────────────┬─port─┬─status─┬─error─┬─num_hosts_remaining─┬─num_hosts_active─┐
  7. │ chi-sample-01-cluster1-1-090000 │ │ 30
  8. │ chi-sample-01-cluster1-0-090000 │ │ 20
  9. │ chi-sample-01-cluster1-1-190000 │ │ 10
  10. │ chi-sample-01-cluster1-0-190000 │ │ 00
  11. └────────────────────────────┴──────┴────────┴───────┴─────────────────────┴──────────────────┘
  12. 4 rows in set. Elapsed: 0.143 sec.

5)插入数据

INSERT INTO events SELECT today(), rand()%3, number, 'my title' FROM numbers(100);

6)进入其他pod查看

  1. kubectl -n ckk8s exec -it chi-sample-01-cluster1-0-1-0 /bin/bash
  2. kubectl -n ckk8s exec -it chi-sample-01-cluster1-1-0-0 /bin/bash
  3. kubectl -n ckk8s exec -it chi-sample-01-cluster1-1-1-0 /bin/bash

将其改为2分片1副本,修改sample-storage.yaml,然后部署

kubectl apply -f sample-storage.yaml -n ckk8s

查看pod

  1. kubectl get pod -n ckk8s
  2. NAME READY STATUS RESTARTS AGE
  3. chi-sample-01-cluster1-0-0-0 1/1 Running 0 150m
  4. chi-sample-01-cluster1-0-1-0 1/1 Terminating 0 150m
  5. chi-sample-01-cluster1-1-0-0 1/1 Running 0 148m
  6. chi-sample-01-cluster1-1-1-0 1/1 Terminating 0 147m
  7. NAME READY STATUS RESTARTS AGE
  8. chi-sample-01-cluster1-0-0-0 1/1 Running 0 150m
  9. chi-sample-01-cluster1-1-0-0 1/1 Running 0 148m
  10. chi-sample-01-cluster1-1-1-0 0/1 Terminating 0 147m
  11. NAME READY STATUS RESTARTS AGE
  12. chi-sample-01-cluster1-0-0-0 1/1 Running 0 151m
  13. chi-sample-01-cluster1-1-0-0 1/1 Running 0 149m

发现在变少

进入这两个pod,发现表和数据还在

  1. chi-sample-01-cluster1-1-0-0.chi-sample-01-cluster1-1-0.ckk8s.svc.cluster.local :) show tables;
  2. SHOW TABLES
  3. Query id: d999a560-cb35-4de3-85ea-dd07182ad1a0
  4. ┌─name─────────┐
  5. │ events │
  6. │ events_local │
  7. └──────────────┘
  8. 2 rows in set. Elapsed: 0.003 sec.
  9. chi-sample-01-cluster1-1-0-0.chi-sample-01-cluster1-1-0.ckk8s.svc.cluster.local :) select count() from events;
  10. SELECT count()
  11. FROM events
  12. Query id: 5a33d098-239a-4ff9-96ee-1feb005b2e6f
  13. ┌─count()─┐
  14. 100
  15. └─────────┘
  16. 1 rows in set. Elapsed: 0.009 sec.

将其改为3分片2副本,修改sample-storage.yaml,然后部署

kubectl apply -f sample-storage.yaml -n ckk8s

查看pod

  1. kubectl get pod -n ckk8s
  2. NAME READY STATUS RESTARTS AGE
  3. chi-sample-01-cluster1-0-0-0 1/1 Running 0 154m
  4. chi-sample-01-cluster1-0-1-0 0/1 ContainerCreating 0 1s
  5. chi-sample-01-cluster1-1-0-0 1/1 Running 0 152m
  6. NAME READY STATUS RESTARTS AGE
  7. chi-sample-01-cluster1-0-0-0 1/1 Running 0 155m
  8. chi-sample-01-cluster1-0-1-0 1/1 Running 0 68s
  9. chi-sample-01-cluster1-1-0-0 1/1 Running 0 153m
  10. chi-sample-01-cluster1-1-1-0 1/1 Running 0 30s
  11. chi-sample-01-cluster1-2-0-0 0/1 ContainerCreating 0 1s
  12. NAME READY STATUS RESTARTS AGE
  13. chi-sample-01-cluster1-0-0-0 1/1 Running 0 158m
  14. chi-sample-01-cluster1-0-1-0 1/1 Running 0 3m56s
  15. chi-sample-01-cluster1-1-0-0 1/1 Running 0 156m
  16. chi-sample-01-cluster1-1-1-0 1/1 Running 0 3m18s
  17. chi-sample-01-cluster1-2-0-0 1/1 Running 0 2m49s
  18. chi-sample-01-cluster1-2-1-0 1/1 Running 0 2m27s

进入新的pod查看,发现表和数据被复制过去

  1. root@chi-sample-01-cluster1-2-1-0:/# clickhouse-client
  2. ClickHouse client version 21.8.5.7 (official build).
  3. Connecting to localhost:9000 as user default.
  4. Connected to ClickHouse server version 21.8.5 revision 54449.
  5. chi-sample-01-cluster1-2-1-0.chi-sample-01-cluster1-2-1.ckk8s.svc.cluster.local :) show tables;
  6. SHOW TABLES
  7. Query id: 9b7e443e-449b-4d0a-ab13-7e410e4ecc01
  8. ┌─name─────────┐
  9. │ events │
  10. │ events_local │ │
  11. └──────────────┘

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/338756
推荐阅读
相关标签
  

闽ICP备14008679号