├── .gitignore ├── .helmignore ├── CHANGELOG.md ├── Chart.yaml ├── LICENSE ├── README.md ├── TODO.md ├── docs ├── README.md ├── application.md ├── development.md ├── examples │ ├── application-values.yaml │ ├── nginx-values.yaml │ └── postgres-values.yaml ├── nginx.md └── postgres.md ├── hack ├── generate-index.sh ├── test-deploy.sh ├── test-dryrun.sh └── test-values │ ├── configmap-subpath.yaml │ ├── dnsconfig.yaml │ ├── expected-results │ ├── configmap-subpath.yaml │ ├── dnsconfig.yaml │ ├── normal.yaml │ ├── secret-file-deployment.yaml │ ├── secret-file-sts.yaml │ └── secretenv.yaml │ ├── normal.yaml │ ├── secret-file-deployment.yaml │ ├── secret-file-sts.yaml │ ├── secretenv.yaml │ └── sts.yaml ├── index.yaml ├── robots.txt ├── templates ├── NOTES.txt ├── _helpers.tpl ├── _pod.tpl ├── _rbac.yaml ├── configmap.yaml ├── deployment.yaml ├── ingress.yaml ├── pvc.yaml ├── rbac.yaml ├── secret-docker.yaml ├── service.yaml └── statefulset.yaml └── values.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | app-*.tgz 2 | 3 | # Helm Charts dependencies 4 | /charts 5 | *.lock 6 | 7 | .idea 8 | -------------------------------------------------------------------------------- /.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | 6 | # Common VCS dirs 7 | .git/ 8 | .gitignore 9 | .bzr/ 10 | .bzrignore 11 | .hg/ 12 | .hgignore 13 | .svn/ 14 | 15 | # Common backup files 16 | *.swp 17 | *.bak 18 | *.tmp 19 | *~ 20 | *.tgz 21 | # Various IDEs 22 | .project 23 | .idea/ 24 | *.tmproj 25 | 26 | .circleci/ 27 | .github/ -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | v0.13.0: 2 | - Use Pod template for StatefulSet and Deployment 3 | - Add `dnsConfig` and `dnsPolicy` fields to Pod template 4 | - Improve document for testing helm chart 5 | 6 | v0.12.0: 7 | - Add `secrets` in volumes to mount secret files into Pods 8 | - Add examples and docs to deploy postgres, nginx and web application 9 | - Improve testing and add it to development doc 10 | 11 | v0.11.0: 12 | - Set default value of `resources` to nil 13 | - Set default value of `services` to empty list 14 | - Add `subPath` for configmap 15 | - Improve test scripts and reorganize hack directory 16 | 17 | v0.10.2 18 | - Add `podLabels` to label `Deployment` and `Statefulset` pods 19 | 20 | v0.10.1: 21 | - Correct `pathType` in values file 22 | - Add `tls` section to ingress object 23 | 24 | v0.10.0: 25 | - Replace `volumes.pvc.existing_claim` with `volumes.pvc.existingClaim` 26 | - Set default value of `volumes.pvc.existingClaim` explicitly to null 27 | - Do not create PVC if there is an existing claim (i.e. `volumes.pvc.existingClaim` is 28 | not null) 29 | 30 | v0.9.0: 31 | - Change command and args usage 32 | - Set default value of configmaps to empty list 33 | 34 | v0.8.0: 35 | - Add securityContext for deployment and sts 36 | - Add podSecurityContext for deployment and sts 37 | 38 | v0.7.1: 39 | - Do not create Deployment if `deployment: false` 40 | - Fix problem with ConfigMap and Service 41 | 42 | v0.7.0: 43 | - Add statefulset 44 | - Add test for statefulset 45 | - Delete some template yaml files 46 | - Use Secret data as environment variable 47 | 48 | v0.6.1: 49 | - SubPath for PVC mounted on the pod 50 | 51 | v0.6.0: 52 | - Add node selector and tolerations 53 | - Add update strategy for deployment 54 | - Add hostNetwork for deployment 55 | -------------------------------------------------------------------------------- /Chart.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: v2 3 | name: app 4 | version: 0.13.0 5 | appVersion: 0.13.0 6 | description: A Helm chart to deploy (almost) all your services 7 | keywords: 8 | - application 9 | - template 10 | - DRY 11 | - generic 12 | source: 13 | - https://github.com/aahemm/helm-microservice 14 | maintainers: 15 | - name: aliakbar-hemmati 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Helm Chart To Deploy (Almost) All Your Services 2 | 3 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) ![version](https://img.shields.io/github/tag/aahemm/helm-microservice.svg?label=release) 4 | 5 | ## Overview 6 | 7 | This helm chart provides a solution for everyone who wants to deploy their applications 8 | on Kubernetes. It is designed to make the deployment and management of your stateful 9 | and stateless services as seamless and efficient as possible. It can be used with helm, 10 | helmfile, GitOps and any other helm related tools. 11 | 12 | ## Features 13 | - Easy installation and configuration 14 | - Customizable settings to fit your specific needs using ConfigMaps and environment 15 | variables 16 | - Supports both StatefulSet and Deployment in Kubernetes 17 | - Manage workload scheduling using node selectors, tolerations and affinities 18 | - Define ingress resources and services that expose your application 19 | - And much more! 20 | 21 | ## Prerequisites 22 | 23 | - Kubernetes cluster 1.10+ 24 | - Helm 3.0.0+ 25 | 26 | ## Installation 27 | 28 | First add the helm repo: 29 | ```bash 30 | helm repo add app https://aahemm.github.io/helm-microservice 31 | helm repo update 32 | ``` 33 | 34 | Then you need to write a values file to deploy your specific application. For configurations options, please 35 | see the [values.yaml](values.yaml) file. This file lists the configurable parameters of the chart and the 36 | default values. It also provides some hints on how to use them. 37 | 38 | After configuring the desired values in `values.yaml` file, install the 39 | helm chart with a release name `my-release`: 40 | 41 | ```bash 42 | helm install my-release app/app --values ./values.yaml 43 | ``` 44 | 45 | To uninstall/delete the `my-release` deployment: 46 | 47 | ```bash 48 | helm uninstall my-release 49 | ``` 50 | 51 | 52 | ## Documentation 53 | For more information on how to use this helm chart, refer to [docs](./docs/README.md) or 54 | [examples](./docs/examples/). 55 | 56 | 57 | ## Contributing 58 | 59 | We welcome and appreciate contributions from the community. 60 | If you have any ideas, suggestions, or improvements, feel free to open 61 | an issue or submit a pull request. 62 | 63 | 64 | ## License 65 | 66 | Thid project is licensed under Apache License 2.0. See the [LICENSE](/LICENSE) 67 | for details. 68 | 69 | 70 | 71 | Thank you for choosing this helm chart! I hope it helps you in deploying 72 | and managing your services effectively. -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | - [ ] add multiple pvcs 2 | - [ ] remove template-ish files in `templates` for resources 3 | - [ ] automatic creation of helm package and index 4 | - [x] add statefulset 5 | - [ ] clean up default `values.yaml` file 6 | - [x] improve readme.md 7 | - [ ] hostAliases 8 | - [ ] do not create configmap if it is empty in `values.yaml` 9 | - [ ] add labels to all objects 10 | - [ ] add labels to specific objects (deployment, pod, etc.) 11 | - [ ] create cronjob 12 | - [ ] improve values for pvc and configmap 13 | - [x] use secret as config file in pods 14 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | ## Example Scenarios 2 | There are some examples that you can read and deploy to start using this chart: 3 | - [nginx](./nginx.md) 4 | - [postgres](./postgres.md) 5 | - [web application](./application.md) 6 | 7 | If you want to develop this chart go to [development guide](./development.md). 8 | -------------------------------------------------------------------------------- /docs/application.md: -------------------------------------------------------------------------------- 1 | In this part we want to deploy a web application. You can replace it with your own image but here we use ... 2 | The values to have a sample app can be found in [this file](./examples/application-values.yaml). 3 | We set the replicas to 1: 4 | ```yaml 5 | global: 6 | replicaCount: 1 7 | ``` 8 | You can increase it and upgrade your helm release whenever you want. 9 | Then comes the image info: 10 | ```yaml 11 | image: 12 | repository: "stefanprodan/podinfo" 13 | tag: "latest" 14 | pullPolicy: Always 15 | ``` 16 | The tag may be changed if you need another version of the image. 17 | To expose application define Service: 18 | ```yaml 19 | services: 20 | - name: web 21 | type: ClusterIP 22 | annotations: {} 23 | specs: 24 | - port: 9898 25 | targetPort: 9898 26 | name: web 27 | ``` 28 | 29 | Then we define ingress: 30 | ```yaml 31 | ingress: 32 | enabled: true 33 | annotations: 34 | traefik.ingress.kubernetes.io/router.entrypoints: websecure 35 | traefik.ingress.kubernetes.io/router.tls: "true" 36 | traefik.ingress.kubernetes.io/router.tls.certresolver: "letsencrypt" 37 | hosts: 38 | - host: api.example.com 39 | servicePort: 9898 40 | serviceName: web 41 | path: / 42 | pathType: Prefix 43 | tls: [] 44 | ``` 45 | This ingress is for Traefik. Adjust it based on your ingress controller. 46 | 47 | And finally the resources: 48 | ```yaml 49 | resources: 50 | limits: 51 | cpu: 100m 52 | memory: 200Mi 53 | requests: 54 | cpu: 100m 55 | memory: 200Mi 56 | ``` 57 | 58 | This is not mandatory but it is a good practice to define resources for Pods. 59 | Now you have the values to deploy the application. Install it with a command like: 60 | ```sh 61 | helm install backend app/app --values ./values.yaml 62 | ``` 63 | 64 | And have fun! 65 | -------------------------------------------------------------------------------- /docs/development.md: -------------------------------------------------------------------------------- 1 | ## Create a package from chart: 2 | - Update chart version in `Chart.yaml` file 3 | - Run `helm package .` in the root of project 4 | - Move the generated `app-$version.tgz` file to `hack/` 5 | - Run `./generate-index.sh $version` in `hack/` and copy new lines in `hack/index.taml` to `index.yaml` 6 | - Upload the `.tgz` file to releases 7 | - Commit changes and push it to github 8 | 9 | ## Test new version of chart 10 | - Run `helm template ./ --values ./hack/test-values/secret-file-deployment.yaml > /tmp/helm-result.yaml` in the root of the project 11 | - Compare outputs: `diff /tmp/helm-result.yaml hack/test-values/expected-results/some-file.yaml` 12 | - For each new test result in `hack/test-values/expected-results` run this in the root of the project: 13 | ```sh 14 | helm template ./ --values ./hack/test-values/secret-file-deployment.yaml > ./hack/test-values/expected-results/secret-file-deployment.yaml 15 | ``` -------------------------------------------------------------------------------- /docs/examples/application-values.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | 4 | image: 5 | repository: "stefanprodan/podinfo" 6 | tag: "latest" 7 | pullPolicy: Always 8 | 9 | services: 10 | - name: web 11 | type: ClusterIP 12 | annotations: {} 13 | specs: 14 | - port: 9898 15 | targetPort: 9898 16 | name: web 17 | 18 | ingress: 19 | enabled: true 20 | annotations: 21 | traefik.ingress.kubernetes.io/router.entrypoints: websecure 22 | traefik.ingress.kubernetes.io/router.tls: "true" 23 | traefik.ingress.kubernetes.io/router.tls.certresolver: "letsencrypt" 24 | hosts: 25 | - host: api.example.com 26 | servicePort: 9898 27 | serviceName: web 28 | path: / 29 | pathType: Prefix 30 | tls: [] 31 | 32 | resources: 33 | limits: 34 | cpu: 100m 35 | memory: 200Mi 36 | requests: 37 | cpu: 100m 38 | memory: 200Mi 39 | -------------------------------------------------------------------------------- /docs/examples/nginx-values.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | 4 | image: 5 | repository: "nginx" 6 | tag: "1.24.0" 7 | pullPolicy: Always 8 | 9 | services: 10 | - name: web 11 | type: NodePort 12 | annotations: {} 13 | specs: 14 | - port: 80 15 | targetPort: 80 16 | nodePort: 30080 17 | name: web 18 | 19 | volumes: 20 | enabled: true 21 | pvc: 22 | enabled: false 23 | configMaps: 24 | - name: nginx-config 25 | mountPath: /etc/nginx/conf.d/ 26 | data: 27 | default.conf: | 28 | server { 29 | listen 80; 30 | listen [::]:80; 31 | 32 | server_name www.example.com; 33 | 34 | location / { 35 | proxy_pass http://localhost:8000; 36 | proxy_set_header Host $http_host; 37 | proxy_set_header X-Real-IP $remote_addr; 38 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 39 | proxy_set_header X-Forwarded-Proto $scheme; 40 | } 41 | } 42 | 43 | resources: 44 | limits: 45 | cpu: 100m 46 | memory: 200Mi 47 | requests: 48 | cpu: 100m 49 | memory: 200Mi 50 | -------------------------------------------------------------------------------- /docs/examples/postgres-values.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | 4 | image: 5 | repository: "postgres" 6 | tag: "14.7" 7 | pullPolicy: Always 8 | 9 | deployment: false 10 | 11 | services: 12 | - name: db 13 | type: ClusterIP 14 | annotations: {} 15 | specs: 16 | - port: 5432 17 | targetPort: 5432 18 | name: db 19 | 20 | environment: 21 | POSTGRES_PASSWORD: password 22 | POSTGRES_USER: postgres 23 | POSTGRES_DB: postgres 24 | PGDATA: /var/lib/postgresql/data/pgdata 25 | 26 | volumes: 27 | enabled: true 28 | pvc: 29 | enabled: true 30 | name: postgres 31 | mountPath: /var/lib/postgresql/data 32 | size: 2G 33 | accessModes: 34 | - ReadWriteOnce 35 | configMaps: [] 36 | 37 | resources: 38 | limits: 39 | cpu: 500m 40 | memory: 1000Mi 41 | requests: 42 | cpu: 500m 43 | memory: 1000Mi 44 | -------------------------------------------------------------------------------- /docs/nginx.md: -------------------------------------------------------------------------------- 1 | The values to have a sample nginx can be found in [this file](./examples/nginx-values.yaml). 2 | We set the replicas to 1: 3 | ```yaml 4 | global: 5 | replicaCount: 1 6 | ``` 7 | You can increase it and upgrade your helm release whenever you want. 8 | Then comes the nginx image info: 9 | ```yaml 10 | image: 11 | repository: "nginx" 12 | tag: "1.24.0" 13 | pullPolicy: Always 14 | ``` 15 | The tag may be changed if you need another version of nginx. 16 | To expose nginx define Service: 17 | ```yaml 18 | services: 19 | - name: web 20 | type: NodePort 21 | annotations: {} 22 | specs: 23 | - port: 80 24 | targetPort: 80 25 | nodePort: 30080 26 | name: web 27 | ``` 28 | 29 | To have custom nginx config use ConfigMaps: 30 | ```yaml 31 | volumes: 32 | enabled: true 33 | pvc: 34 | enabled: false 35 | configMaps: 36 | - name: nginx-config 37 | mountPath: /etc/nginx/conf.d/ 38 | data: 39 | default.conf: | 40 | server { 41 | listen 80; 42 | listen [::]:80; 43 | 44 | server_name www.example.com; 45 | 46 | location / { 47 | proxy_pass http://localhost:8000; 48 | proxy_set_header Host $http_host; 49 | proxy_set_header X-Real-IP $remote_addr; 50 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 51 | proxy_set_header X-Forwarded-Proto $scheme; 52 | } 53 | } 54 | ``` 55 | Change nginx config as you wish. The name of the key(s) in `.volumes.configMaps[*].data` will become the file 56 | names mounted in the Pod. 57 | Set the `.volumes.pvc.enabled` to `false` because we do not need PVC for nginx. 58 | And finally the resources: 59 | ```yaml 60 | resources: 61 | limits: 62 | cpu: 100m 63 | memory: 200Mi 64 | requests: 65 | cpu: 100m 66 | memory: 200Mi 67 | ``` 68 | This is not mandatory but it is a good practice to define resources for Pods. 69 | Now you have the values to deploy nginx. Install it with a command like: 70 | ```sh 71 | helm install nginx app/app --values ./values.yaml 72 | ``` 73 | 74 | And have fun! 75 | -------------------------------------------------------------------------------- /docs/postgres.md: -------------------------------------------------------------------------------- 1 | The values to have a sample postgres can be found in [this file](./examples/postgres-values.yaml). 2 | We set the replicas to 1: 3 | ```yaml 4 | global: 5 | replicaCount: 1 6 | ``` 7 | Then comes the postgres image info: 8 | ```yaml 9 | image: 10 | repository: "postgres" 11 | tag: "14.7" 12 | pullPolicy: Always 13 | ``` 14 | The tag may be changed if you need another version of postgres. 15 | 16 | Postgres is a stateful service. So we want to deploy it using a StatefulSet. Here we do this: 17 | ```yaml 18 | deployment: false 19 | ``` 20 | 21 | To expose postgres define Service: 22 | ```yaml 23 | services: 24 | - name: db 25 | type: ClusterIP 26 | annotations: {} 27 | specs: 28 | - port: 5432 29 | targetPort: 5432 30 | name: db 31 | ``` 32 | 33 | Postgres image needs some environment variables. So we put this block and define variables in there: 34 | ```yaml 35 | environment: 36 | POSTGRES_PASSWORD: password 37 | POSTGRES_USER: postgres 38 | POSTGRES_DB: postgres 39 | PGDATA: /var/lib/postgresql/data/pgdata 40 | ``` 41 | 42 | To persist postgres data create a PVC: 43 | ```yaml 44 | volumes: 45 | enabled: true 46 | pvc: 47 | enabled: true 48 | name: postgres 49 | mountPath: /var/lib/postgresql/data 50 | size: 2G 51 | accessModes: 52 | - ReadWriteOnce 53 | configMaps: [] 54 | ``` 55 | All the PVC parameters are set here. You need a default StoragClass for this to work. 56 | 57 | And finally the resources: 58 | ```yaml 59 | resources: 60 | limits: 61 | cpu: 500m 62 | memory: 1000Mi 63 | requests: 64 | cpu: 500m 65 | memory: 1000Mi 66 | ``` 67 | This is not mandatory but it is a good practice to define resources for Pods. 68 | 69 | Now you have the values to deploy postgres. Install it with a command like: 70 | ```sh 71 | helm install postgres app/app --values ./values.yaml 72 | ``` 73 | 74 | And have fun! -------------------------------------------------------------------------------- /hack/generate-index.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -ex 3 | if [ -z $1 ] 4 | then 5 | echo "Please provide the release" 6 | exit 1 7 | fi 8 | 9 | release=$1 10 | url="https://github.com/aahemm/helm-microservice/releases/download/v$release" 11 | helm repo index ./ --merge index.yaml --url $url 12 | -------------------------------------------------------------------------------- /hack/test-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | values_file_path=$1 5 | helm upgrade -i --debug --values $values_file_path test-app ../ 6 | -------------------------------------------------------------------------------- /hack/test-dryrun.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | values_file_path=$1 5 | helm install --debug --dry-run --values $values_file_path app ../ 6 | -------------------------------------------------------------------------------- /hack/test-values/configmap-subpath.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | 4 | image: 5 | repository: "nginx" 6 | tag: "1.21.6" 7 | pullPolicy: IfNotPresent 8 | 9 | #replicaCount: 1 10 | deployment: false 11 | 12 | volumes: 13 | enabled: true 14 | configMaps: 15 | - name: test 16 | mountPath: /usr/share/nginx/html/file.conf 17 | subPath: file.conf 18 | data: 19 | file.conf: | 20 | another hello 21 | 22 | 23 | 24 | nodeSelector: {} 25 | 26 | tolerations: [] 27 | 28 | affinity: {} 29 | 30 | 31 | -------------------------------------------------------------------------------- /hack/test-values/dnsconfig.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | environment: {} 4 | 5 | image: 6 | repository: nginx 7 | tag: "1.21.3" 8 | pullPolicy: IfNotPresent 9 | 10 | services: 11 | - name: web 12 | type: ClusterIP 13 | annotations: {} 14 | specs: 15 | - port: 8000 16 | targetPort: 8000 17 | name: http 18 | 19 | volumes: 20 | enabled: true 21 | pvc: 22 | enabled: true 23 | existingClaim: null 24 | name: my-data 25 | mountPath: "" 26 | subPaths: 27 | - mountPath: /data 28 | subPath: data 29 | - mountPath: /var/lib/logs 30 | subPath: logs 31 | size: 1G 32 | accessModes: 33 | - ReadWriteOnce 34 | 35 | configMaps: [] 36 | 37 | dnsPolicy: "None" 38 | dnsConfig: 39 | nameservers: 40 | - 10.202.10.202 41 | - 10.202.10.102 42 | -------------------------------------------------------------------------------- /hack/test-values/expected-results/configmap-subpath.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Source: app/templates/configmap.yaml 3 | apiVersion: v1 4 | kind: ConfigMap 5 | metadata: 6 | name: test 7 | data: 8 | # property-like keys; each key maps to a simple value 9 | file.conf: |- 10 | another hello 11 | --- 12 | # Source: app/templates/statefulset.yaml 13 | apiVersion: apps/v1 14 | kind: StatefulSet 15 | metadata: 16 | name: release-name-app 17 | labels: 18 | app.kubernetes.io/name: app 19 | helm.sh/chart: app-0.11.0 20 | app.kubernetes.io/instance: release-name 21 | app.kubernetes.io/managed-by: Helm 22 | spec: 23 | serviceName: release-name 24 | replicas: 1 25 | selector: 26 | matchLabels: 27 | app.kubernetes.io/name: app 28 | app.kubernetes.io/instance: release-name 29 | template: 30 | metadata: 31 | labels: 32 | app.kubernetes.io/name: app 33 | app.kubernetes.io/instance: release-name 34 | spec: 35 | securityContext: 36 | {} 37 | automountServiceAccountToken: false 38 | hostNetwork: false 39 | containers: 40 | - name: app 41 | securityContext: 42 | {} 43 | image: "nginx:1.21.6" 44 | imagePullPolicy: IfNotPresent 45 | ports: 46 | volumeMounts: 47 | - mountPath: /usr/share/nginx/html/file.conf 48 | name: test-volume 49 | subPath: file.conf 50 | resources: 51 | {} 52 | volumes: 53 | - name: test-volume 54 | configMap: 55 | name: test 56 | --- 57 | # Source: app/templates/rbac.yaml 58 | #RBAC and service account 59 | -------------------------------------------------------------------------------- /hack/test-values/expected-results/dnsconfig.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Source: app/templates/pvc.yaml 3 | apiVersion: v1 4 | kind: PersistentVolumeClaim 5 | metadata: 6 | name: my-data 7 | spec: 8 | accessModes: 9 | - ReadWriteOnce 10 | resources: 11 | requests: 12 | storage: 1G 13 | --- 14 | # Source: app/templates/service.yaml 15 | apiVersion: v1 16 | kind: Service 17 | metadata: 18 | name: release-name-app-svc-web 19 | labels: 20 | app.kubernetes.io/name: release-name-app-svc-web 21 | helm.sh/chart: app-0.13.0 22 | app.kubernetes.io/instance: release-name 23 | app.kubernetes.io/managed-by: Helm 24 | spec: 25 | type: ClusterIP 26 | selector: 27 | app.kubernetes.io/name: app 28 | app.kubernetes.io/instance: release-name 29 | ports: 30 | - name: http 31 | port: 8000 32 | protocol: TCP 33 | targetPort: 8000 34 | --- 35 | # Source: app/templates/deployment.yaml 36 | apiVersion: apps/v1 37 | kind: Deployment 38 | metadata: 39 | name: release-name-app 40 | labels: 41 | app.kubernetes.io/name: app 42 | helm.sh/chart: app-0.13.0 43 | app.kubernetes.io/instance: release-name 44 | app.kubernetes.io/managed-by: Helm 45 | spec: 46 | replicas: 1 47 | selector: 48 | matchLabels: 49 | app.kubernetes.io/name: app 50 | app.kubernetes.io/instance: release-name 51 | template: 52 | metadata: 53 | labels: 54 | app.kubernetes.io/name: app 55 | app.kubernetes.io/instance: release-name 56 | spec: 57 | 58 | dnsPolicy: None 59 | dnsConfig: 60 | nameservers: 61 | - 10.202.10.202 62 | - 10.202.10.102 63 | securityContext: 64 | {} 65 | automountServiceAccountToken: false 66 | hostNetwork: false 67 | containers: 68 | - name: app 69 | securityContext: 70 | {} 71 | image: "nginx:1.21.3" 72 | imagePullPolicy: IfNotPresent 73 | ports: 74 | - name: http 75 | containerPort: 8000 76 | protocol: TCP 77 | volumeMounts: 78 | - mountPath: /data 79 | name: my-data-volume 80 | subPath: data 81 | - mountPath: /var/lib/logs 82 | name: my-data-volume 83 | subPath: logs 84 | resources: 85 | {} 86 | volumes: 87 | - name: my-data-volume 88 | persistentVolumeClaim: 89 | claimName: my-data 90 | --- 91 | # Source: app/templates/rbac.yaml 92 | #RBAC and service account 93 | -------------------------------------------------------------------------------- /hack/test-values/expected-results/normal.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Source: app/templates/pvc.yaml 3 | apiVersion: v1 4 | kind: PersistentVolumeClaim 5 | metadata: 6 | name: my-data 7 | spec: 8 | accessModes: 9 | - ReadWriteOnce 10 | resources: 11 | requests: 12 | storage: 1G 13 | --- 14 | # Source: app/templates/service.yaml 15 | apiVersion: v1 16 | kind: Service 17 | metadata: 18 | name: release-name-app-svc-web 19 | labels: 20 | app.kubernetes.io/name: release-name-app-svc-web 21 | helm.sh/chart: app-0.11.0 22 | app.kubernetes.io/instance: release-name 23 | app.kubernetes.io/managed-by: Helm 24 | spec: 25 | type: ClusterIP 26 | selector: 27 | app.kubernetes.io/name: app 28 | app.kubernetes.io/instance: release-name 29 | ports: 30 | - name: http 31 | port: 8000 32 | protocol: TCP 33 | targetPort: 8000 34 | --- 35 | # Source: app/templates/deployment.yaml 36 | apiVersion: apps/v1 37 | kind: Deployment 38 | metadata: 39 | name: release-name-app 40 | labels: 41 | app.kubernetes.io/name: app 42 | helm.sh/chart: app-0.11.0 43 | app.kubernetes.io/instance: release-name 44 | app.kubernetes.io/managed-by: Helm 45 | spec: 46 | replicas: 1 47 | selector: 48 | matchLabels: 49 | app.kubernetes.io/name: app 50 | app.kubernetes.io/instance: release-name 51 | template: 52 | metadata: 53 | labels: 54 | app.kubernetes.io/name: app 55 | app.kubernetes.io/instance: release-name 56 | spec: 57 | securityContext: 58 | {} 59 | automountServiceAccountToken: false 60 | hostNetwork: false 61 | containers: 62 | - name: app 63 | securityContext: 64 | {} 65 | image: "nginx:1.21.3" 66 | imagePullPolicy: IfNotPresent 67 | ports: 68 | - name: http 69 | containerPort: 8000 70 | protocol: TCP 71 | volumeMounts: 72 | - mountPath: /data 73 | name: my-data-volume 74 | subPath: data 75 | - mountPath: /var/lib/logs 76 | name: my-data-volume 77 | subPath: logs 78 | resources: 79 | {} 80 | volumes: 81 | - name: my-data-volume 82 | persistentVolumeClaim: 83 | claimName: my-data 84 | --- 85 | # Source: app/templates/rbac.yaml 86 | #RBAC and service account 87 | -------------------------------------------------------------------------------- /hack/test-values/expected-results/secret-file-deployment.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Source: app/templates/deployment.yaml 3 | apiVersion: apps/v1 4 | kind: Deployment 5 | metadata: 6 | name: release-name-app 7 | labels: 8 | app.kubernetes.io/name: app 9 | helm.sh/chart: app-0.11.0 10 | app.kubernetes.io/instance: release-name 11 | app.kubernetes.io/managed-by: Helm 12 | spec: 13 | replicas: 1 14 | selector: 15 | matchLabels: 16 | app.kubernetes.io/name: app 17 | app.kubernetes.io/instance: release-name 18 | template: 19 | metadata: 20 | labels: 21 | app.kubernetes.io/name: app 22 | app.kubernetes.io/instance: release-name 23 | spec: 24 | securityContext: 25 | {} 26 | automountServiceAccountToken: false 27 | hostNetwork: false 28 | containers: 29 | - name: app 30 | securityContext: 31 | {} 32 | image: "aahemm/podinfo:v0.12.0" 33 | imagePullPolicy: IfNotPresent 34 | ports: 35 | volumeMounts: 36 | - mountPath: /test-secret 37 | name: test-secret-volume 38 | - mountPath: /etc/myfile.conf 39 | name: test-secret-2-volume 40 | subPath: myfile.conf 41 | resources: 42 | {} 43 | volumes: 44 | - name: test-secret-volume 45 | secret: 46 | secretName: test-secret 47 | - name: test-secret-2-volume 48 | secret: 49 | secretName: test-secret-2 50 | --- 51 | # Source: app/templates/rbac.yaml 52 | #RBAC and service account 53 | -------------------------------------------------------------------------------- /hack/test-values/expected-results/secret-file-sts.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Source: app/templates/statefulset.yaml 3 | apiVersion: apps/v1 4 | kind: StatefulSet 5 | metadata: 6 | name: release-name-app 7 | labels: 8 | app.kubernetes.io/name: app 9 | helm.sh/chart: app-0.11.0 10 | app.kubernetes.io/instance: release-name 11 | app.kubernetes.io/managed-by: Helm 12 | spec: 13 | serviceName: release-name 14 | replicas: 1 15 | selector: 16 | matchLabels: 17 | app.kubernetes.io/name: app 18 | app.kubernetes.io/instance: release-name 19 | template: 20 | metadata: 21 | labels: 22 | app.kubernetes.io/name: app 23 | app.kubernetes.io/instance: release-name 24 | spec: 25 | securityContext: 26 | {} 27 | automountServiceAccountToken: false 28 | hostNetwork: false 29 | containers: 30 | - name: app 31 | securityContext: 32 | {} 33 | image: "aahemm/podinfo:v0.12.0" 34 | imagePullPolicy: IfNotPresent 35 | ports: 36 | volumeMounts: 37 | - mountPath: /test-secret 38 | name: test-secret-volume 39 | - mountPath: /etc/myfile.conf 40 | name: test-secret-2-volume 41 | subPath: myfile.conf 42 | resources: 43 | {} 44 | volumes: 45 | - name: test-secret-volume 46 | secret: 47 | secretName: test-secret 48 | - name: test-secret-2-volume 49 | secret: 50 | secretName: test-secret-2 51 | --- 52 | # Source: app/templates/rbac.yaml 53 | #RBAC and service account 54 | -------------------------------------------------------------------------------- /hack/test-values/expected-results/secretenv.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # Source: app/templates/pvc.yaml 3 | apiVersion: v1 4 | kind: PersistentVolumeClaim 5 | metadata: 6 | name: my-data 7 | spec: 8 | accessModes: 9 | - ReadWriteOnce 10 | resources: 11 | requests: 12 | storage: 1G 13 | --- 14 | # Source: app/templates/service.yaml 15 | apiVersion: v1 16 | kind: Service 17 | metadata: 18 | name: release-name-app-svc-web 19 | labels: 20 | app.kubernetes.io/name: release-name-app-svc-web 21 | helm.sh/chart: app-0.11.0 22 | app.kubernetes.io/instance: release-name 23 | app.kubernetes.io/managed-by: Helm 24 | spec: 25 | type: ClusterIP 26 | selector: 27 | app.kubernetes.io/name: app 28 | app.kubernetes.io/instance: release-name 29 | ports: 30 | - name: http 31 | port: 8000 32 | protocol: TCP 33 | targetPort: 8000 34 | --- 35 | # Source: app/templates/deployment.yaml 36 | apiVersion: apps/v1 37 | kind: Deployment 38 | metadata: 39 | name: release-name-app 40 | labels: 41 | app.kubernetes.io/name: app 42 | helm.sh/chart: app-0.11.0 43 | app.kubernetes.io/instance: release-name 44 | app.kubernetes.io/managed-by: Helm 45 | spec: 46 | replicas: 1 47 | selector: 48 | matchLabels: 49 | app.kubernetes.io/name: app 50 | app.kubernetes.io/instance: release-name 51 | template: 52 | metadata: 53 | labels: 54 | app.kubernetes.io/name: app 55 | app.kubernetes.io/instance: release-name 56 | spec: 57 | securityContext: 58 | {} 59 | automountServiceAccountToken: false 60 | hostNetwork: false 61 | containers: 62 | - name: app 63 | securityContext: 64 | {} 65 | image: "myrepo.com/my-image:v1.2.3" 66 | imagePullPolicy: IfNotPresent 67 | ports: 68 | - name: http 69 | containerPort: 8000 70 | protocol: TCP 71 | envFrom: 72 | - secretRef: 73 | name: "secretOne" 74 | - secretRef: 75 | name: "secretTwo" 76 | volumeMounts: 77 | - mountPath: /data 78 | name: my-data-volume 79 | subPath: data 80 | - mountPath: /var/lib/logs 81 | name: my-data-volume 82 | subPath: logs 83 | resources: 84 | limits: 85 | cpu: 100m 86 | memory: 200Mi 87 | requests: 88 | cpu: 100m 89 | memory: 200Mi 90 | volumes: 91 | - name: my-data-volume 92 | persistentVolumeClaim: 93 | claimName: my-data 94 | --- 95 | # Source: app/templates/rbac.yaml 96 | #RBAC and service account 97 | -------------------------------------------------------------------------------- /hack/test-values/normal.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | environment: {} 4 | 5 | image: 6 | repository: nginx 7 | tag: "1.21.3" 8 | pullPolicy: IfNotPresent 9 | 10 | services: 11 | - name: web 12 | type: ClusterIP 13 | annotations: {} 14 | specs: 15 | - port: 8000 16 | targetPort: 8000 17 | name: http 18 | 19 | volumes: 20 | enabled: true 21 | pvc: 22 | enabled: true 23 | existingClaim: null 24 | name: my-data 25 | mountPath: "" 26 | subPaths: 27 | - mountPath: /data 28 | subPath: data 29 | - mountPath: /var/lib/logs 30 | subPath: logs 31 | size: 1G 32 | accessModes: 33 | - ReadWriteOnce 34 | 35 | 36 | configMaps: [] 37 | -------------------------------------------------------------------------------- /hack/test-values/secret-file-deployment.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | 4 | image: 5 | repository: "aahemm/podinfo" 6 | tag: "v0.12.0" 7 | pullPolicy: IfNotPresent 8 | 9 | volumes: 10 | enabled: true 11 | pvc: 12 | enabled: false 13 | secrets: 14 | - name: test-secret 15 | mountPath: /test-secret 16 | - name: test-secret-2 17 | mountPath: /etc/myfile.conf 18 | subPath: myfile.conf 19 | configMaps: [] 20 | -------------------------------------------------------------------------------- /hack/test-values/secret-file-sts.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | 4 | image: 5 | repository: "aahemm/podinfo" 6 | tag: "v0.12.0" 7 | pullPolicy: IfNotPresent 8 | 9 | deployment: false 10 | 11 | volumes: 12 | enabled: true 13 | pvc: 14 | enabled: false 15 | secrets: 16 | - name: test-secret 17 | mountPath: /test-secret 18 | - name: test-secret-2 19 | mountPath: /etc/myfile.conf 20 | subPath: myfile.conf 21 | configMaps: [] 22 | -------------------------------------------------------------------------------- /hack/test-values/secretenv.yaml: -------------------------------------------------------------------------------- 1 | # Default values for microservice. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | global: 6 | replicaCount: 1 7 | environment: {} 8 | # list of key: value 9 | # GLOBAL1: value 10 | 11 | hostNetwork: false 12 | ## Set default image, imageTag, and imagePullPolicy. 13 | ## ref: https://hub.docker.com/r/apache/nifi/ 14 | ## 15 | image: 16 | repository: "myrepo.com/my-image" 17 | tag: "v1.2.3" 18 | pullPolicy: IfNotPresent 19 | 20 | #replicaCount: 1 21 | 22 | # command: ["/bin/sh","-c"] 23 | # args: ["echo 'consuming a message'; sleep 5"] 24 | deployment: true 25 | nameOverride: "" 26 | fullnameOverride: "" 27 | 28 | ## Optionally specify an imagePullSecret. 29 | ## Secret must be manually created in the namespace. 30 | ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ 31 | ## 32 | 33 | #imagePullSecrets: myRegistrKeySecretName 34 | imageCredentials: {} 35 | # registry: https://index.docker.io/v1/ 36 | # username: username 37 | # password: password 38 | # email: tsorage@cetic.be 39 | 40 | #serviceAccount: microservice-sa 41 | createServiceAccount: false 42 | rbac: false 43 | 44 | # Annotation for the Deployment 45 | annotations: {} 46 | 47 | # List of services 48 | services: 49 | - name: web 50 | type: ClusterIP 51 | annotations: {} 52 | specs: 53 | - port: 8000 54 | targetPort: 8000 55 | name: http 56 | #targetPort: is the port the container accepts traffic on, 57 | #port: is the abstracted Service port, which can be any port other pods use to access the Service 58 | #https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#serviceport-v1-core 59 | secretEnv: 60 | enabled: true 61 | secretNames: 62 | - secretOne 63 | - secretTwo 64 | environment: {} 65 | # VAR1: value1 66 | 67 | #Probes 68 | liveness: 69 | enabled: false 70 | path: /alive 71 | port: 8001 72 | initialDelaySeconds: 3 73 | periodSeconds: 3 74 | readiness: 75 | enabled: false 76 | path: /ready 77 | port: 8001 78 | initialDelaySeconds: 5 79 | periodSeconds: 5 80 | failureThreshold: 3 81 | 82 | 83 | updateStrategy: {} 84 | ## for stateless apps, Default 85 | # type: RollingUpdate 86 | # rollingUpdate: {} 87 | 88 | ## for stateful apps: 89 | # type: Recreate 90 | 91 | volumes: 92 | enabled: true 93 | pvc: 94 | enabled: true 95 | existingClaim: null 96 | name: my-data 97 | mountPath: "" 98 | # if subPath is used mountPath must be empty 99 | subPaths: 100 | - mountPath: /data 101 | subPath: data 102 | - mountPath: /var/lib/logs 103 | subPath: logs 104 | size: 1G 105 | class: 106 | accessModes: 107 | - ReadWriteOnce 108 | 109 | # configFileCommonHeader: | 110 | # line1 111 | # line2 112 | 113 | configMaps: [] 114 | 115 | # - name: test-from-file 116 | # mountPath: /test2 117 | # files: 118 | # - source: config.conf 119 | # destination: application.conf 120 | # - name: test-mixed 121 | # mountPath: /test3 122 | # data: 123 | # test2.conf: | 124 | # another hello 125 | # files: 126 | # - source: config.conf 127 | # destination: application2.conf 128 | 129 | 130 | ingress: 131 | enabled: false 132 | annotations: {} 133 | # kubernetes.io/ingress.class: nginx 134 | # kubernetes.io/tls-acme: "true" 135 | hosts: 136 | - host: chart-example.local 137 | servicePort: 8000 138 | serviceName: web 139 | path: / 140 | tls: [] 141 | pathType: Prefix 142 | # - secretName: chart-example-tls 143 | # hosts: 144 | # - chart-example.local 145 | 146 | nodeSelector: {} 147 | 148 | tolerations: [] 149 | 150 | affinity: {} 151 | 152 | resources: 153 | limits: 154 | cpu: 100m 155 | memory: 200Mi 156 | requests: 157 | cpu: 100m 158 | memory: 200Mi 159 | 160 | -------------------------------------------------------------------------------- /hack/test-values/sts.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | replicaCount: 1 3 | environment: {} 4 | # list of key: value 5 | # GLOBAL1: value 6 | 7 | deployment: false 8 | hostNetwork: false 9 | 10 | image: 11 | repository: "myrepo.com/my-image" 12 | tag: "v1.2.3" 13 | pullPolicy: IfNotPresent 14 | 15 | #replicaCount: 1 16 | 17 | # command: ["/bin/sh","-c"] 18 | # args: ["echo 'consuming a message'; sleep 5"] 19 | 20 | nameOverride: "" 21 | fullnameOverride: "" 22 | 23 | #serviceAccount: microservice-sa 24 | createServiceAccount: false 25 | rbac: false 26 | 27 | # Annotation for the Deployment 28 | annotations: {} 29 | 30 | # List of services 31 | services: 32 | - name: web 33 | type: ClusterIP 34 | annotations: {} 35 | specs: 36 | - port: 8000 37 | targetPort: 8000 38 | name: http 39 | 40 | environment: 41 | VAR1: value1 42 | 43 | #Probes 44 | liveness: 45 | enabled: false 46 | path: /alive 47 | port: 8001 48 | initialDelaySeconds: 3 49 | periodSeconds: 3 50 | readiness: 51 | enabled: false 52 | path: /ready 53 | port: 8001 54 | initialDelaySeconds: 5 55 | periodSeconds: 5 56 | failureThreshold: 3 57 | 58 | 59 | updateStrategy: {} 60 | ## for stateless apps, Default 61 | # type: RollingUpdate 62 | # rollingUpdate: {} 63 | 64 | ## for stateful apps: 65 | # type: Recreate 66 | 67 | volumes: 68 | enabled: true 69 | pvc: 70 | enabled: true 71 | existingClaim: null 72 | name: my-data 73 | mountPath: "" 74 | # if subPath is used mountPath must be empty 75 | subPaths: 76 | - mountPath: /data 77 | subPath: data 78 | - mountPath: /var/lib/logs 79 | subPath: logs 80 | size: 1G 81 | class: 82 | accessModes: 83 | - ReadWriteOnce 84 | configMaps: 85 | - name: test 86 | mountPath: /test 87 | data: 88 | test.conf: | 89 | hello 90 | 91 | ingress: 92 | enabled: false 93 | annotations: {} 94 | # kubernetes.io/ingress.class: nginx 95 | # kubernetes.io/tls-acme: "true" 96 | hosts: 97 | - host: chart-example.local 98 | servicePort: 8000 99 | serviceName: web 100 | path: / 101 | tls: [] 102 | pathType: Prefix 103 | 104 | 105 | nodeSelector: {} 106 | 107 | tolerations: [] 108 | 109 | affinity: {} 110 | 111 | resources: 112 | limits: 113 | cpu: 100m 114 | memory: 200Mi 115 | requests: 116 | cpu: 100m 117 | memory: 200Mi 118 | 119 | -------------------------------------------------------------------------------- /index.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | entries: 3 | app: 4 | - apiVersion: v2 5 | appVersion: 0.13.0 6 | created: "2023-12-30T21:41:09.704001684+03:30" 7 | description: A Helm chart to deploy (almost) all your services 8 | digest: 0baf3a8a5eb19a39ac99afc73889b22f74346e7bf41f473a374db095a0bff787 9 | keywords: 10 | - application 11 | - template 12 | - DRY 13 | - generic 14 | maintainers: 15 | - name: aliakbar-hemmati 16 | name: app 17 | urls: 18 | - https://github.com/aahemm/helm-microservice/releases/download/v0.13.0/app-0.13.0.tgz 19 | version: 0.13.0 20 | - apiVersion: v2 21 | appVersion: 0.12.0 22 | created: "2023-11-18T22:41:22.31170348+03:30" 23 | description: A Helm chart to deploy (almost) all your services 24 | digest: 530ef8230b42e010a70f05689484a41672f1d0305b857a453b444568e75dec43 25 | keywords: 26 | - application 27 | - template 28 | - DRY 29 | - generic 30 | maintainers: 31 | - name: aliakbar-hemmati 32 | name: app 33 | urls: 34 | - https://github.com/aahemm/helm-microservice/releases/download/v0.12.0/app-0.12.0.tgz 35 | version: 0.12.0 36 | - apiVersion: v2 37 | appVersion: 0.11.0 38 | created: "2023-09-18T16:54:33.230602037+03:30" 39 | description: A Helm chart which provides a DRY application deployment mechanism 40 | digest: 53ccd1c4146c12c8ee9200ff2248f3441acfa1377e32bbb397741b150342369b 41 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 42 | keywords: 43 | - application 44 | - template 45 | - DRY 46 | - generic 47 | maintainers: 48 | - name: aliakbar-hemmati 49 | name: app 50 | urls: 51 | - https://github.com/aahemm/helm-microservice/releases/download/v0.11.0/app-0.11.0.tgz 52 | version: 0.11.0 53 | - apiVersion: v2 54 | appVersion: 0.10.2 55 | created: "2023-08-31T15:50:02.035454106+03:30" 56 | description: A Helm chart which provides a DRY application deployment mechanism 57 | digest: 78157785f45c6060a2ee185138057c80af18b4ee28cf172981e5759d5acb0558 58 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 59 | keywords: 60 | - application 61 | - template 62 | - DRY 63 | - generic 64 | maintainers: 65 | - name: aliakbar-hemmati 66 | name: app 67 | urls: 68 | - https://github.com/aahemm/helm-microservice/releases/download/v0.10.2/app-0.10.2.tgz 69 | version: 0.10.2 70 | - apiVersion: v2 71 | appVersion: 0.10.1 72 | created: "2023-07-30T14:16:01.970472775+03:30" 73 | description: A Helm chart which provides a DRY application deployment mechanism 74 | digest: a42f1b02d972629d54fa252973d07e4dd1c0a4c5d3a386289d0260f6d4dbf203 75 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 76 | keywords: 77 | - application 78 | - template 79 | - DRY 80 | - generic 81 | maintainers: 82 | - name: aliakbar-hemmati 83 | name: app 84 | urls: 85 | - https://github.com/aahemm/helm-microservice/releases/download/v0.10.1/app-0.10.1.tgz 86 | version: 0.10.1 87 | - apiVersion: v2 88 | appVersion: 0.10.0 89 | created: "2023-05-16T07:19:44.645809072+03:30" 90 | description: A Helm chart which provides a DRY application deployment mechanism 91 | digest: 7597b345c164f10c9c20c560d42946d3c97f6de69791162ff023ff6df857cc1c 92 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 93 | keywords: 94 | - application 95 | - template 96 | - DRY 97 | - generic 98 | maintainers: 99 | - name: aliakbar-hemmati 100 | name: app 101 | urls: 102 | - https://github.com/aahemm/helm-microservice/releases/download/v0.10.0/app-0.10.0.tgz 103 | version: 0.10.0 104 | - apiVersion: v2 105 | appVersion: 0.9.0 106 | created: "2023-05-13T14:49:35.548985227+03:30" 107 | description: A Helm chart which provides a DRY application deployment mechanism 108 | digest: 7267da5519c4eef8fd0ce666e16bc0074dba27101539a93bc062bb909bdfcef3 109 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 110 | keywords: 111 | - application 112 | - template 113 | - DRY 114 | - generic 115 | maintainers: 116 | - name: aliakbar-hemmati 117 | name: app 118 | urls: 119 | - https://github.com/aahemm/helm-microservice/releases/download/v0.9.0/app-0.9.0.tgz 120 | version: 0.9.0 121 | - apiVersion: v2 122 | appVersion: 0.8.0 123 | created: "2023-04-30T18:22:17.638784345+03:30" 124 | description: A Helm chart which provides a DRY application deployment mechanism 125 | digest: 49abe9c8aa84b2f5ee5448eaf071b9cdc182af321c5703d0d2ac67b67735e87b 126 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 127 | keywords: 128 | - application 129 | - template 130 | - DRY 131 | - generic 132 | maintainers: 133 | - name: aliakbar-hemmati 134 | name: app 135 | urls: 136 | - https://github.com/aahemm/helm-microservice/releases/download/v0.8.0/app-0.8.0.tgz 137 | version: 0.8.0 138 | - apiVersion: v2 139 | appVersion: 0.7.1 140 | created: "2023-04-08T15:41:18.11595894+03:30" 141 | description: A Helm chart which provides a DRY application deployment mechanism 142 | digest: 37449dad5aa1a51f9bb88098f5ea6a447ff8d469a20e0784d409f8fb03eb7b3b 143 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 144 | keywords: 145 | - application 146 | - template 147 | - DRY 148 | - generic 149 | maintainers: 150 | - name: aliakbar-hemmati 151 | name: app 152 | urls: 153 | - https://github.com/aahemm/helm-microservice/releases/download/v0.7.1/app-0.7.1.tgz 154 | version: 0.7.1 155 | - apiVersion: v2 156 | appVersion: 0.6.1 157 | created: "2023-01-09T19:57:25.390486413+03:30" 158 | description: A Helm chart which provides a DRY application deployment mechanism 159 | digest: 1ee8eee34857ed3083ece4b22ca75533c5b73a2f03e65a2de948d780903ef442 160 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 161 | keywords: 162 | - application 163 | - template 164 | - DRY 165 | - generic 166 | maintainers: 167 | - name: aliakbar-hemmati 168 | name: app 169 | urls: 170 | - https://github.com/aahemm/helm-microservice/releases/download/v0.6.1/app-0.6.1.tgz 171 | version: 0.6.1 172 | - apiVersion: v2 173 | appVersion: 0.6.0 174 | created: "2023-01-09T19:57:25.389179257+03:30" 175 | description: A Helm chart which provides a DRY application deployment mechanism 176 | digest: 06792030c27906d164827daa12866f3414396a9ffebe357eece70b682e35e13c 177 | icon: https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png 178 | keywords: 179 | - application 180 | - template 181 | - DRY 182 | - generic 183 | maintainers: 184 | - name: aliakbar-hemmati 185 | name: app 186 | urls: 187 | - https://github.com/aahemm/helm-microservice/releases/download/v0.6.0/app-0.6.0.tgz 188 | version: 0.6.0 189 | generated: "2023-01-09T19:57:25.387554486+03:30" 190 | -------------------------------------------------------------------------------- /robots.txt: -------------------------------------------------------------------------------- 1 | “User-Agent: *nDisallow: /” 2 | -------------------------------------------------------------------------------- /templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | Microservice deployed. 2 | Proxy command for reaching the services: 3 | {{- $root:= . -}} 4 | {{- range $service:= .Values.services -}} 5 | {{- range $spec:= .specs }} 6 | kubectl port-forward svc/{{ include "microservice.fullname" $root }}-svc-{{ $service.name }} {{ $spec.containerPort | default $spec.port }}:{{ $spec.port }} 7 | {{- end }} 8 | {{- end }} -------------------------------------------------------------------------------- /templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* Generate basic labels */}} 2 | {{- define "chart.label" }} 3 | labels: 4 | app.kubernetes.io/name: {{ include "microservice.name" . }} 5 | helm.sh/chart: {{ include "microservice.chart" . }} 6 | app.kubernetes.io/instance: {{ .Release.Name }} 7 | app.kubernetes.io/managed-by: {{ .Release.Service }} 8 | {{- end -}} 9 | 10 | {{/* vim: set filetype=mustache: */}} 11 | {{/* 12 | Expand the name of the chart. 13 | */}} 14 | {{- define "microservice.name" -}} 15 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 16 | {{- end }} 17 | 18 | {{/* 19 | Create a default fully qualified app name. 20 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 21 | If release name contains chart name it will be used as a full name. 22 | */}} 23 | {{- define "microservice.fullname" -}} 24 | {{- if .Values.fullnameOverride -}} 25 | {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} 26 | {{- else -}} 27 | {{- $name := default .Chart.Name .Values.nameOverride -}} 28 | {{- if contains $name .Release.Name -}} 29 | {{- .Release.Name | trunc 63 | trimSuffix "-" -}} 30 | {{- else -}} 31 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 32 | {{- end -}} 33 | {{- end -}} 34 | {{- end -}} 35 | 36 | {{/* 37 | Create chart name and version as used by the chart label. 38 | */}} 39 | {{- define "microservice.chart" -}} 40 | {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} 41 | {{- end -}} 42 | 43 | 44 | 45 | {{/* 46 | Create docker credentials. 47 | */}} 48 | {{- define "docker_credentials_tpl" }} 49 | {{- with .Values.imageCredentials }} 50 | {{- printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" .registry .username .password .email (printf "%s:%s" .username .password | b64enc) | b64enc }} 51 | {{- end }} 52 | {{- end }} 53 | -------------------------------------------------------------------------------- /templates/_pod.tpl: -------------------------------------------------------------------------------- 1 | {{- define "microservice.pod" -}} 2 | {{- if or .Values.imagePullSecrets .Values.imageCredentials }} 3 | imagePullSecrets: 4 | {{- end }} 5 | {{- if .Values.imagePullSecrets }} 6 | - name: {{ .Values.imagePullSecrets }} 7 | {{- end }} 8 | {{- if .Values.dnsPolicy }} 9 | dnsPolicy: {{ .Values.dnsPolicy }} 10 | {{- end }} 11 | {{- with .Values.dnsConfig }} 12 | dnsConfig: 13 | {{- toYaml . | nindent 2 }} 14 | {{- end }} 15 | {{- if .Values.imageCredentials }} 16 | - name: {{ include "microservice.name" . }}-docker-credentials 17 | {{- end }} 18 | {{- if .Values.serviceAccount }} 19 | serviceAccountName: {{ .Values.serviceAccount }} 20 | {{- end }} 21 | securityContext: 22 | {{- toYaml .Values.podSecurityContext | nindent 2 }} 23 | automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} 24 | {{- if .Values.hostAliases }} 25 | hostAliases: 26 | {{- range .Values.hostAliases }} 27 | - ip: {{ .ip }} 28 | hostnames: 29 | {{- range .hostnames }} 30 | - {{ . }} 31 | {{- end }} 32 | {{- end }} 33 | {{- end }} 34 | hostNetwork: {{ .Values.hostNetwork }} 35 | containers: 36 | - name: {{ .Chart.Name }} 37 | securityContext: 38 | {{- toYaml .Values.securityContext | nindent 6 }} 39 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" 40 | imagePullPolicy: {{ .Values.image.pullPolicy }} 41 | {{- if .Values.setCommand }} 42 | command: 43 | - /bin/sh 44 | - -c 45 | {{- end }} 46 | {{- if .Values.args }} 47 | args: 48 | - {{ .Values.args }} 49 | {{- end }} 50 | ports: 51 | {{- range .Values.services -}} 52 | {{- range $port:= .specs}} 53 | - name: {{ .name }} 54 | containerPort: {{ .targetPort | default .port}} 55 | protocol: {{ .protocol | default "TCP" }} 56 | {{- end }} 57 | {{- end }} 58 | {{- if (merge .Values.global.environment .Values.environment) }} 59 | env: 60 | {{- range $name, $value := merge .Values.global.environment .Values.environment }} 61 | - name: {{ $name | quote }} 62 | value: {{ $value | quote }} 63 | {{- end }} 64 | {{- end }} 65 | {{- if .Values.secretEnv.enabled }} 66 | envFrom: 67 | {{- range $name := .Values.secretEnv.secretNames }} 68 | - secretRef: 69 | name: {{ $name | quote }} 70 | {{- end }} 71 | {{- end }} 72 | {{- if .Values.volumes.enabled }} 73 | volumeMounts: 74 | {{- range $conf := .Values.volumes.configMaps }} 75 | - mountPath: {{ $conf.mountPath }} 76 | name: {{ $conf.name }}-volume 77 | {{- if $conf.subPath }} 78 | subPath: {{ $conf.subPath }} 79 | {{- end }} 80 | {{- end }} 81 | {{- range $sec := .Values.volumes.secrets }} 82 | - mountPath: {{ $sec.mountPath }} 83 | name: {{ $sec.name }}-volume 84 | {{- if $sec.subPath }} 85 | subPath: {{ $sec.subPath }} 86 | {{- end }} 87 | {{- end }} 88 | {{- if .Values.volumes.pvc.enabled }} 89 | {{- if .Values.volumes.pvc.mountPath }} 90 | - mountPath: {{ .Values.volumes.pvc.mountPath }} 91 | name: {{ .Values.volumes.pvc.existingClaim | default .Values.volumes.pvc.name }}-volume 92 | {{- else }} 93 | {{- $vols := .Values.volumes }} 94 | {{- range $subpath := $vols.pvc.subPaths }} 95 | - mountPath: {{ $subpath.mountPath }} 96 | name: {{ $vols.pvc.existingClaim | default $vols.pvc.name }}-volume 97 | subPath: {{ $subpath.subPath }} 98 | {{- end }} 99 | {{- end }} 100 | {{- end }} 101 | {{- end }} 102 | resources: 103 | {{- toYaml .Values.resources | nindent 6 }} 104 | {{- if .Values.liveness.enabled }} 105 | livenessProbe: 106 | httpGet: 107 | path: {{ .Values.liveness.path }} 108 | port: {{ .Values.liveness.port }} 109 | initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }} 110 | periodSeconds: {{ .Values.liveness.periodSeconds }} 111 | {{- end}} 112 | {{- if .Values.readiness.enabled }} 113 | readinessProbe: 114 | httpGet: 115 | path: {{ .Values.readiness.path }} 116 | port: {{ .Values.readiness.port }} 117 | initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }} 118 | periodSeconds: {{ .Values.readiness.periodSeconds }} 119 | failureThreshold: {{ .Values.readiness.failureThreshold }} 120 | {{- end }} 121 | {{- with .Values.nodeSelector }} 122 | nodeSelector: 123 | {{- toYaml . | nindent 2 }} 124 | {{- end }} 125 | {{- with .Values.affinity }} 126 | affinity: 127 | {{- toYaml . | nindent 2 }} 128 | {{- end }} 129 | {{- with .Values.tolerations }} 130 | tolerations: 131 | {{- toYaml . | nindent 2 }} 132 | {{- end }} 133 | {{- if .Values.volumes.enabled }} 134 | volumes: 135 | {{- range $conf := .Values.volumes.configMaps }} 136 | - name: {{ $conf.name }}-volume 137 | configMap: 138 | name: {{ $conf.name }} 139 | {{- end }} 140 | {{- range $sec := .Values.volumes.secrets }} 141 | - name: {{ $sec.name }}-volume 142 | secret: 143 | secretName: {{ $sec.name }} 144 | {{- end }} 145 | {{- if .Values.volumes.pvc.enabled }} 146 | - name: {{ .Values.volumes.pvc.existingClaim | default .Values.volumes.pvc.name }}-volume 147 | persistentVolumeClaim: 148 | claimName: {{ .Values.volumes.pvc.existingClaim | default .Values.volumes.pvc.name }} 149 | {{- end }} 150 | {{- end }} 151 | {{- end -}} -------------------------------------------------------------------------------- /templates/_rbac.yaml: -------------------------------------------------------------------------------- 1 | {{- define "rbac" -}} 2 | #RBAC and service account 3 | {{- $sa := .Values.serviceAccount | default "default" }} 4 | {{- if .Values.createServiceAccount }} 5 | apiVersion: v1 6 | kind: ServiceAccount 7 | metadata: 8 | name: {{ $sa }} 9 | namespace: {{ .Release.Namespace }} 10 | --- 11 | {{- end }} 12 | {{- if .Values.rbac }} 13 | apiVersion: v1 14 | kind: List 15 | items: 16 | #define the rights 17 | - apiVersion: rbac.authorization.k8s.io/v1 18 | kind: ClusterRole 19 | metadata: 20 | name: {{ .Release.Name }}-cr-{{ .Release.Namespace }} 21 | rules: 22 | - apiGroups: 23 | - "apps" 24 | resources: 25 | - deployments 26 | - statefulsets 27 | verbs: 28 | - get 29 | - list 30 | #link the ClusterRole to the namespace 31 | - apiVersion: rbac.authorization.k8s.io/v1 32 | kind: ClusterRoleBinding 33 | metadata: 34 | name: {{ .Release.Name }}-crb-{{ .Release.Namespace }} 35 | subjects: 36 | - kind: ServiceAccount 37 | name: {{ $sa }} 38 | namespace: {{ .Release.Namespace }} 39 | roleRef: 40 | kind: ClusterRole 41 | name: {{ .Release.Name }}-cr-{{ .Release.Namespace }} 42 | apiGroup: rbac.authorization.k8s.io 43 | {{- end }} 44 | {{- end -}} -------------------------------------------------------------------------------- /templates/configmap.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.volumes.configMaps }} 2 | {{- if .Values.volumes.enabled }} 3 | {{ $root := . }} 4 | {{ range $cm := .Values.volumes.configMaps}} 5 | --- 6 | apiVersion: v1 7 | kind: ConfigMap 8 | metadata: 9 | name: {{ $cm.name }} 10 | data: 11 | {{- if $cm.data }} 12 | {{- range $filename, $content := $cm.data }} 13 | # property-like keys; each key maps to a simple value 14 | {{ $filename }}: |- 15 | {{ $content | toString | indent 4}} 16 | {{- end }} 17 | {{- end }} 18 | {{- if $cm.files }} 19 | {{- range $file := $cm.files }} 20 | {{ $file.destination }}: | 21 | {{ $root.Files.Get $file.source }} 22 | {{- end}} 23 | {{- end }} 24 | {{- end }} 25 | {{- end }} 26 | {{- end }} 27 | 28 | -------------------------------------------------------------------------------- /templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | {{ if .Values.deployment -}} 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: {{ include "microservice.fullname" . }} 6 | {{- if .Values.annotations }} 7 | annotations: 8 | {{- range $key, $value := .Values.annotations }} 9 | {{ $key }}: {{ $value }} 10 | {{- end }} 11 | {{- end }} 12 | labels: 13 | app.kubernetes.io/name: {{ include "microservice.name" . }} 14 | helm.sh/chart: {{ include "microservice.chart" . }} 15 | app.kubernetes.io/instance: {{ .Release.Name }} 16 | app.kubernetes.io/managed-by: {{ .Release.Service }} 17 | spec: 18 | replicas: {{ .Values.replicaCount | default .Values.global.replicaCount }} 19 | {{- if .Values.updateStrategy }} 20 | strategy: {{- toYaml .Values.updateStrategy | nindent 4 }} 21 | {{- end }} 22 | selector: 23 | matchLabels: 24 | app.kubernetes.io/name: {{ include "microservice.name" . }} 25 | app.kubernetes.io/instance: {{ .Release.Name }} 26 | template: 27 | metadata: 28 | labels: 29 | app.kubernetes.io/name: {{ include "microservice.name" . }} 30 | app.kubernetes.io/instance: {{ .Release.Name }} 31 | {{- with .Values.podLabels }} 32 | {{- toYaml . | nindent 8 }} 33 | {{- end }} 34 | spec: 35 | {{- include "microservice.pod" . | nindent 6 }} 36 | {{- end }} 37 | -------------------------------------------------------------------------------- /templates/ingress.yaml: -------------------------------------------------------------------------------- 1 | {{- $root:= . }} 2 | {{- if .Values.ingress.enabled -}} 3 | apiVersion: networking.k8s.io/v1 4 | kind: Ingress 5 | metadata: 6 | name: {{ include "microservice.fullname" . }} 7 | labels: 8 | app.kubernetes.io/name: {{ include "microservice.fullname" . }} 9 | helm.sh/chart: {{ include "microservice.chart" . }} 10 | app.kubernetes.io/instance: {{ .Release.Name }} 11 | app.kubernetes.io/managed-by: {{ .Release.Service }} 12 | {{- with .Values.ingress.annotations }} 13 | annotations: 14 | {{- toYaml . | nindent 4 }} 15 | {{- end }} 16 | spec: 17 | {{- with .Values.ingress.tls }} 18 | tls: 19 | {{- toYaml . | nindent 4 }} 20 | {{- end }} 21 | rules: 22 | {{- range .Values.ingress.hosts }} 23 | - host: {{ .host | quote }} 24 | http: 25 | paths: 26 | - path: {{ .path }} 27 | pathType: {{ .pathType }} 28 | backend: 29 | service: 30 | name: {{ include "microservice.fullname" $root }}-svc-{{ .serviceName }} 31 | port: 32 | number: {{ .servicePort }} 33 | {{- end }} 34 | {{- end -}} 35 | -------------------------------------------------------------------------------- /templates/pvc.yaml: -------------------------------------------------------------------------------- 1 | {{- if and (.Values.volumes.pvc.enabled) (not .Values.volumes.pvc.existingClaim) }} 2 | apiVersion: v1 3 | kind: PersistentVolumeClaim 4 | metadata: 5 | name: {{ .Values.volumes.pvc.name }} 6 | spec: 7 | {{- if .Values.volumes.pvc.class }} 8 | storageClassName: {{ .Values.volumes.pvc.class }} 9 | {{- end }} 10 | accessModes: 11 | {{- range $accessMode := .Values.volumes.pvc.accessModes }} 12 | - {{ $accessMode }} 13 | {{- end }} 14 | resources: 15 | requests: 16 | storage: {{ .Values.volumes.pvc.size }} 17 | {{- end }} -------------------------------------------------------------------------------- /templates/rbac.yaml: -------------------------------------------------------------------------------- 1 | {{- include "rbac" . -}} -------------------------------------------------------------------------------- /templates/secret-docker.yaml: -------------------------------------------------------------------------------- 1 | {{- if .Values.imageCredentials }} 2 | apiVersion: v1 3 | kind: Secret 4 | metadata: 5 | name: {{ include "microservice.name" . }}-docker-credentials 6 | namespace: {{ .Release.Namespace }} 7 | type: kubernetes.io/dockerconfigjson 8 | data: 9 | .dockerconfigjson: {{ template "docker_credentials_tpl" . }} 10 | {{- end }} -------------------------------------------------------------------------------- /templates/service.yaml: -------------------------------------------------------------------------------- 1 | {{- $root:= . }} 2 | {{- range $service := .Values.services}} 3 | --- 4 | apiVersion: v1 5 | kind: Service 6 | metadata: 7 | name: {{ include "microservice.fullname" $root }}-svc-{{ $service.name }} 8 | {{- if $service.annotations }} 9 | annotations: 10 | {{- range $key, $value := $service.annotations }} 11 | {{ $key }}: {{ $value }} 12 | {{- end }} 13 | {{- end }} 14 | labels: 15 | app.kubernetes.io/name: {{ include "microservice.fullname" $root }}-svc-{{ $service.name }} 16 | helm.sh/chart: {{ include "microservice.chart" $root }} 17 | app.kubernetes.io/instance: {{ $root.Release.Name }} 18 | app.kubernetes.io/managed-by: {{ $root.Release.Service }} 19 | spec: 20 | type: {{ $service.type }} 21 | selector: 22 | app.kubernetes.io/name: {{ include "microservice.name" $root }} 23 | app.kubernetes.io/instance: {{ $root.Release.Name }} 24 | ports: 25 | {{- range $spec := $service.specs }} 26 | - name: {{ $spec.name }} 27 | port: {{ $spec.port }} 28 | protocol: {{ $spec.protocol | default "TCP" }} 29 | {{- if $spec.targetPort }} 30 | targetPort: {{ $spec.targetPort }} 31 | {{- end}} 32 | {{- if $spec.nodePort }} 33 | nodePort: {{ $spec.nodePort }} 34 | {{- end }} 35 | {{- end -}} 36 | {{- end -}} 37 | -------------------------------------------------------------------------------- /templates/statefulset.yaml: -------------------------------------------------------------------------------- 1 | {{ if not .Values.deployment -}} 2 | apiVersion: apps/v1 3 | kind: StatefulSet 4 | metadata: 5 | name: {{ include "microservice.fullname" . }} 6 | {{- if .Values.annotations }} 7 | annotations: 8 | {{- range $key, $value := .Values.annotations }} 9 | {{ $key }}: {{ $value }} 10 | {{- end }} 11 | {{- end }} 12 | labels: 13 | app.kubernetes.io/name: {{ include "microservice.name" . }} 14 | helm.sh/chart: {{ include "microservice.chart" . }} 15 | app.kubernetes.io/instance: {{ .Release.Name }} 16 | app.kubernetes.io/managed-by: {{ .Release.Service }} 17 | spec: 18 | serviceName: {{ .Release.Name }} 19 | replicas: {{ .Values.replicaCount | default .Values.global.replicaCount }} 20 | selector: 21 | matchLabels: 22 | app.kubernetes.io/name: {{ include "microservice.name" . }} 23 | app.kubernetes.io/instance: {{ .Release.Name }} 24 | template: 25 | metadata: 26 | labels: 27 | app.kubernetes.io/name: {{ include "microservice.name" . }} 28 | app.kubernetes.io/instance: {{ .Release.Name }} 29 | {{- with .Values.podLabels }} 30 | {{- toYaml . | nindent 8 }} 31 | {{- end }} 32 | spec: 33 | {{- include "microservice.pod" . | nindent 6 }} 34 | {{- end }} -------------------------------------------------------------------------------- /values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for microservice. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | 5 | global: 6 | ## If you use `deployment: false` (meaning you are using StatefulSet) set this to 1 or 0 7 | replicaCount: 1 8 | environment: {} 9 | # list of key: value 10 | # GLOBAL1: value 11 | 12 | ## Set this value to true to use Deployment object. 13 | ## If you need StatefulSet set this to false. 14 | deployment: true 15 | 16 | ## If you neeed your pod to have the same network as its host, 17 | ## set this to true 18 | hostNetwork: false 19 | 20 | ## Set default image, imageTag, and imagePullPolicy. 21 | image: 22 | repository: "" 23 | tag: "" 24 | pullPolicy: IfNotPresent 25 | 26 | #replicaCount: 1 27 | 28 | # setCommand: true 29 | # args: "echo 'consuming a message'; sleep 5" 30 | 31 | nameOverride: "" 32 | fullnameOverride: "" 33 | 34 | ## Pod Labels 35 | # podLabels: {} 36 | 37 | ## Optionally specify an imagePullSecret. 38 | ## Secret must be manually created in the namespace. 39 | ## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ 40 | ## 41 | 42 | #imagePullSecrets: myRegistrKeySecretName 43 | imageCredentials: {} 44 | # registry: https://index.docker.io/v1/ 45 | # username: username 46 | # password: password 47 | # email: tsorage@cetic.be 48 | 49 | #serviceAccount: microservice-sa 50 | createServiceAccount: false 51 | rbac: false 52 | 53 | # Annotation for the Deployment 54 | annotations: {} 55 | 56 | # List of services 57 | services: [] 58 | # - name: web 59 | # type: ClusterIP 60 | # annotations: {} 61 | # specs: 62 | # - port: 8000 63 | # targetPort: 8000 64 | # name: http 65 | #targetPort: is the port the container accepts traffic on, 66 | #port: is the abstracted Service port, which can be any port other pods use to access the Service 67 | #https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.16/#serviceport-v1-core 68 | 69 | ## Use a secret that you have created to 70 | ## provide environment variables for the pod. 71 | ## The secret data must be in `key: value` format. 72 | secretEnv: 73 | enabled: false 74 | secretNames: 75 | - secretOne 76 | - secretTwo 77 | 78 | environment: {} 79 | # VAR1: value1 80 | 81 | #Probes 82 | liveness: 83 | enabled: false 84 | path: /alive 85 | port: 8001 86 | initialDelaySeconds: 3 87 | periodSeconds: 3 88 | readiness: 89 | enabled: false 90 | path: /ready 91 | port: 8001 92 | initialDelaySeconds: 5 93 | periodSeconds: 5 94 | failureThreshold: 3 95 | 96 | 97 | updateStrategy: {} 98 | ## For stateless apps, Default 99 | # type: RollingUpdate 100 | # rollingUpdate: {} 101 | 102 | ## For stateful apps 103 | ## It is recommended to set `deployment: false` for 104 | ## stateful apps and not use updateStrategy at all 105 | # type: Recreate 106 | 107 | 108 | volumes: 109 | enabled: false 110 | pvc: 111 | enabled: false 112 | 113 | ## if this is not null the name will be 114 | ## ignored and no pvc will be created 115 | existingClaim: null 116 | name: my-data 117 | mountPath: /pv 118 | # if subPath is used mountPath must be empty 119 | subPaths: 120 | - mountPath: /data 121 | subPath: data 122 | - mountPath: /var/lib/logs 123 | subPath: logs 124 | size: 1G 125 | class: 126 | accessModes: 127 | - ReadWriteOnce 128 | 129 | ## Use secrets to mount file into a Pod 130 | ## The Secret objects must be created before deploying this chart 131 | ## If you use subPath the key in Secret must be same as subPath value 132 | ## Refer to https://kubernetes.io/docs/concepts/configuration/secret/#use-case-dotfiles-in-a-secret-volume for more info 133 | secrets: [] 134 | # - name: test-secret 135 | # mountPath: /test-secret 136 | # - name: test-secret-2 137 | # mountPath: /etc/myfile.conf 138 | # subPath: myfile.conf 139 | 140 | configMaps: [] 141 | # - name: test 142 | # mountPath: /test 143 | # data: 144 | # test.conf: | 145 | # hello 146 | # hello2 147 | 148 | # - name: test-from-file 149 | # mountPath: /test2 150 | # files: 151 | # - source: config.conf 152 | # destination: application.conf 153 | # - name: test-mixed 154 | # mountPath: /test3 155 | # data: 156 | # test2.conf: | 157 | # another hello 158 | # files: 159 | # - source: config.conf 160 | # destination: application2.conf 161 | # - name: test3 162 | # mountPath: /test3/myfilename.conf 163 | # subPath: myfilename.conf 164 | # data: 165 | # myfilename.conf: | 166 | # hello 167 | # hello2 168 | 169 | automountServiceAccountToken: false 170 | 171 | # set dns config for the Pod 172 | dnsConfig: {} 173 | dnsPolicy: null 174 | 175 | ingress: 176 | enabled: false 177 | annotations: {} 178 | # kubernetes.io/ingress.class: nginx 179 | # kubernetes.io/tls-acme: "true" 180 | hosts: 181 | - host: chart-example.local 182 | servicePort: 8000 183 | serviceName: web 184 | path: / 185 | pathType: Prefix 186 | tls: [] 187 | 188 | # - secretName: chart-example-tls 189 | # hosts: 190 | # - chart-example.local 191 | 192 | nodeSelector: {} 193 | 194 | tolerations: [] 195 | 196 | affinity: {} 197 | 198 | resources: {} 199 | # limits: 200 | # cpu: 100m 201 | # memory: 200Mi 202 | # requests: 203 | # cpu: 100m 204 | # memory: 200Mi 205 | 206 | podSecurityContext: {} 207 | # fsGroup: 2000 208 | 209 | securityContext: {} 210 | # capabilities: 211 | # drop: 212 | # - ALL 213 | # readOnlyRootFilesystem: true 214 | # runAsNonRoot: true 215 | # runAsUser: 1000 216 | --------------------------------------------------------------------------------