Create helm chart for a job - kubernetes-helm

I am creating a helm chart for the job I want to run in our k8 cluster. When you execute helm create it creates templates that I do not need.
$ helm create new-job
Creating new-job
$ tree new-job/
new-job/
├── Chart.yaml
├── charts
├── templates
│   ├── NOTES.txt
│   ├── _helpers.tpl
│   ├── deployment.yaml
│   ├── hpa.yaml
│   ├── ingress.yaml
│   ├── service.yaml
│   ├── serviceaccount.yaml
│   └── tests
│   └── test-connection.yaml
└── values.yaml
3 directories, 10 files
Is there a way to only create a template containing only job.yaml?

Helm has the option to use a custom "starter":
helm create --starter /path/to/starter/chart my-chart

There's nothing magical about helm create. Just so long as the chart has a Chart.yaml file and a templates subdirectory, Helm can install it. You can mkdir an empty directory and create the Chart.yaml file from scratch using your favorite text editor, if you'd prefer.
# Chart.yaml, with only the required fields
apiVersion: v2
name: my-chart
version: '0.0.1'
mkdir my-chart; cd my-chart
$EDITOR Chart.yaml
mkdir templates
$EDITOR templates/job.yaml
helm install --generate-name .
You can also go the other direction; start from the helm create template and delete all of the parts you don't need. Of note, there are a couple of generically helpful things in _helpers.tpl you might want to retain. (Keeping the ServiceAccount turns out to be useful in a couple of situations, and if you use Istio, it also likes you to have a Service even if you don't accept inbound connections.)

Related

How to parameterize multiple kubernetes manifests in terraform

I have the following in main.tf
data "kubectl_path_documents" "yaml-files" {
pattern = "${path.module}/manifests/*.yaml"
}
resource "kubectl_manifest" "yaml-manifests" {
for_each = toset(data.kubectl_path_documents.yaml-files.documents)
yaml_body = each.value
}
I would need to parameterize certain fields in the yaml files to be able to deploy different set of resources for dev vs prod. I knew there was a way to do this if it was one yaml. How should this be done for many yaml files
├── manifests
│   ├── gdp-configmap.yaml
│   ├── gdp-agent-deamonset.yaml
│   ├── gdp-collector-configmap.yaml
│   ├── gdp-collector-deployment.yaml
Any help is appreciated.
I was able to resolve this using a null_resource that executes a sh script with values to be sed'ed.

Kubernetes Kustomize patching - Can't patch a file located in base

I have a huge patch file that I want to apply to specific overlays. I usually patch files under overlays as it is supposed to be. But the file is same and I do not want to copy it to each overlay. If I could keep my patch file app-new-manifest.yaml under base and patch it under overlay with a single line in kustomization.yaml, it would be awesome.
├── base
│ ├── app-new-manifest.yaml # I am trying to patch this
│ ├── kustomization.yaml
│ ├── app
│ │ ├── app.yaml
│ │ └── kustomization.yaml
└── overlay
└── environment1
│ ├── kustomization.yaml # I want to patch app-new-manifest.yaml in base
│
└── environment2
│ ├── kustomization.yaml # No patch. app.yaml will be as is
│
└── environment3
├── kustomization.yaml # I want to patch app-new-manifest.yaml in base
When I'm trying to do so, I get this error:
'/base/app/app-new-manifest.yaml' is not in or below '/overlays/environment1'
Which means, when you patch, the patch file has to be located under overlay not base. Is there any workaround to do this? Because copying the same file to each environment does not make sense to me.
Any ideas around this will highly be appreciated, thanks!
Edit:
Add /base/app/kustomization.yaml
resources:
- app.yaml
Add /overlays/environment1/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base/app
patchesStrategicMerge:
- ../../base/app/app-new-manifest.yaml # Patch new manifest
kustomize version:
{Version:kustomize/v4.2.0 GitCommit:d53a2ad45d04b0264bcee9e19879437d851cb778 BuildDate:2021-07-01T00:44:28+01:00 GoOs:darwin GoArch:amd64}
You can't include a file that is outside of you current directory, but you can include another directory that has a kustomize.yaml file. So organize your layout like this:
.
├── base
└── overlay
├── patched_based
├── environment1
├── environment2
└── environment3
In overlay/patched_base, place your patch file and a kustomization file like:
resources:
- ../base
patchesStrategicMerge:
- app-new-manifest.yaml
In overlay/environment1 and overlay/environment3, you have:
resources:
- ../patched_base
Whereas in overlay/environment2, you have:
resources:
- ../../base
I think this solves all your requirements:
You only need a single instance of the patch
You can choose to use the patch or not from each individual overlay

helm chart install - will failed if dependency already installed

I have a few helm charts (each one is a microservice) but a few of them are dependent on
a common chart (some secrets, pvcs, etc)
It is possible to declare dependency between charts and the common chart but if a package
already installed as dependency - the helm chart installation will fail.
I am looking for a way to install a helm chart with dependencies but if one of the dependent charts is already installed, ingone or print a massage but not fail the installation process.
Is there any smart way to handle that ?
Like, check if a prerequisite chart has already been installed and bypass it without failed the whole process.
Thx
Ideally you can give dependencies using
https://helm.sh/docs/helm/helm_dependency/
# Chart.yaml
dependencies:
- name: nginx
version: "1.2.3"
repository: "https://example.com/charts"
- name: memcached
version: "3.2.1"
repository: "https://another.example.com/charts"
Helm charts store their dependencies in 'charts/'. For chart
developers, it is often easier to manage dependencies in 'Chart.yaml'
which declares all dependencies.
The dependency commands operate on that file, making it easy to
synchronize between the desired dependencies and the actual
dependencies stored in the 'charts/' directory.
You can also use the sub chart and parent chart format to manage the dependencies
Folder structure something will go like this
├── Chart.yaml
├── charts
│ └── django
│ ├── Chart.yaml
│ ├── templates
│ │ ├── deployment.yaml
│ │ ├── ingress.yaml
│ │ └── service.yaml
│ └── values.yaml
├── templates
└── values.yaml
For example : https://medium.com/craftech/one-chart-to-rule-them-all-3f685e0f25a9
You can also read more at official documentation : https://helm.sh/docs/chart_template_guide/subcharts_and_globals/
To this point we have been working only with one chart. But charts can
have dependencies, called subcharts, that also have their own values
and templates. In this section we will create a subchart and see the
different ways we can access values from within templates.

Links to json files

my directory structure is
├── xxx
│   ├── 01.md
| └── 02.md
├── auth
│   ├── j1.json
│   ├── j2.json
│   └── j3.json
└── default.template.html
And I link jsons from markdowns like Auth. It makes sense as we use there files as test scenarios and in json files we have credentials and roles. But if I try to generate html it fails on unresolved internal reference: ../auth/aspect_admin.json. I tried to exclude the link checking but without any help. The best would be to leave it as a link in md file but somehow follow the link and include the json as code block in generated html. Is it possible?
It was a bug and will be fixed in next version https://github.com/planet42/Laika/issues/148

Locally building and pushing VuePress site to Github Pages

Having trouble figuring out how the workflow for using Github as a VuePress site source control and deploying it to Github Pages.
When I ran deploy.sh the first time, it gave me a Github certificate error around the init command and did not initialize a new repo (I already have a repo setup so not sure if the init command in deploy.sh is required. Subsequent runs of deploy.sh resulted in no error.
**Problem:**Unfortunately, when I visit my Github Pages site, its not using VuePress templates.
I feel like I have either:
- The folder structure wrong
- The base set incorrectly in config.js
- The relative folders incorrect in deploy.sh
Can someone put eyes on this and give some feedback? Thank you.
For your reference
Local machine's folder structure:
user#system:~/powerDocs$ tree
.
├── deploy.sh
├── docs
│   └── README.md
├── node_modules
│   └── yarn
│   ├── bin
│   │   ├── yarn
│   │   ├── yarn.cmd
│   │   ├── yarn.js
│   │   ├── yarnpkg
│   │   └── yarnpkg.cmd
│   ├── lib
│   │   ├── cli.js
│   │   └── v8-compile-cache.js
│   ├── LICENSE
│   ├── package.json
│   └── README.md
├── package.json
├── package-lock.json
└── README.md
5 directories, 15 files
Content of deploy.sh:
#!/usr/bin/env sh
# abort on errors
set -e
# build
vuepress build
# navigate into the build output directory
cd docs/.vuepress/dist
# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME
git init
git add -A
git commit -m 'deploy'
# if you are deploying to https://<USERNAME>.github.io
# git push -f git#github.com:SeaDude/SeaDude.github.io.git master
# if you are deploying to https://<USERNAME>.github.io/<REPO>
git push -f git#github.com:SeaDude/powerDocs.git master:gh-pages
cd -
I made deploy.sh executable with chmod +x deploy.sh. Running ./deploy.sh gives me the following output:
user#system:~/powerDocs$ ./deploy.sh
WAIT Extracting site metadata...
[12:05:53 PM] Compiling Client
[12:05:53 PM] Compiling Server
(node:15590) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
[12:05:57 PM] Compiled Server in 3s
[12:05:59 PM] Compiled Client in 6s
WAIT Rendering static HTML...
DONE Success! Generated static files in .vuepress/dist.
Reinitialized existing Git repository in /home/powerDocs/docs/.vuepress/dist/.git/
On branch master
nothing to commit, working directory clean
Here is the contents of config.js:
module.exports = {
title: "PowerDocs",
description: "Where functions go to frolic.",
base: "/powerDocs/",
themeConfig: {
nav: [
{ text: "Home", link: "/" }
],
sidebar: [
'/'
]
}
};
Have you checked your dist folder to see what is actually being output? The error makes it seem like there are no files present to commit after the build.
I have the almost identical setup locally and haven't run into this problem with it, the only difference being the command I run to build is yarn docs:build