Helm Cheatsheet: Instantly Share Code, Notes, and Snippets
Helm Cheatsheet: Instantly Share Code, Notes, and Snippets
· GitHub
tuannvm / helm-cheatsheet.md
Last active 4 hours ago
helm-cheatsheet.md
Helm cheatsheet
Helm cheatsheet
Get started
Struture
General Usage
Template
Hooks
Chart repository
Signing
Test
Flow Control
If/Else
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 1/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
With
Range
Variables
Named Templates
Files inside Templates
Glob-patterns & encoding
YAML reference
Get started
https://deis.com/blog/2016/getting-started-authoring-helm-charts/
https://docs.bitnami.com/kubernetes/how-to/
https://github.com/kubernetes/helm/blob/master/docs/charts.md
https://docs.helm.sh/chart-template-guide/
http://helm.readthedocs.io/en/latest/architecture/
Struture
.
├── Chart.yaml --> metadata info
├── README.md
├── requirements.yaml --> define dependencies
├── templates
│ ├── spark-master-deployment.yaml --> configuration with template supported
│ ├── spark-worker-deployment.yaml
│ └── spark-zeppelin-deployment.yaml
│ └── NOTES.txt --> display when run "helm chart"
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 2/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Chart.yaml
requirements.yaml
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 3/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Adding an alias for a dependency chart would put a chart in dependencies using alias as name of new
dependency. Condition - The condition field holds one or more YAML paths (delimited by commas). If this
path exists in the top parent's values and resolves to a boolean value, the chart will be enabled or disabled
based on that boolean value. Only the first valid path found in the list is evaluated and if no paths exist then the
condition has no effect. Tags - The tags field is a YAML list of labels to associate with this chart. In the top
parent's values, all charts with tags can be enabled or disabled by specifying the tag and a boolean value.
Conditions (when set in values) always override tags
dependencies:
- name: apache
version: 1.2.3
repository: http://example.com/charts
alias: new-subchart-1
condition: subchart1.enabled, global.subchart1.enabled
tags:
- front-end
- subchart1
- name: mysql
version: 3.2.1
repository: http://another.example.com/charts
alias: new-subchart-2
condition: subchart2.enabled,global.subchart2.enabled
tags:
- back-end
- subchart1
General Usage
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 4/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
outer:
inner: value
--set servers[0].port=80,servers[0].host=example:
servers:
- port: 80
host: example
name:
- a
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 5/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
- b
- c
--set name=value1,value2:
name: "value1,value2"
--set nodeSelector."kubernetes.io/role"=master
nodeSelector:
kubernetes.io/role: master
livenessProbe:
- httpGet:
- path: /user/login
- port: http
initialDelaySeconds: 120
+ exec:
+ command:
+ - cat
+ - docroot/CHANGELOG.txt
--timeout
--wait
--no-hooks
--recreate-pods
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 6/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Template
Values that are supplied via a values.yaml file (or via the --set flag) are accessible from the .Values object in
a template
Release.Name:
Release.Time:
Release.Namespace: The namespace the chart was released to.
Release.Service: The service that conducted the release. Usually this is Tiller.
Release.IsUpgrade: This is set to true if the current operation is an upgrade or rollback.
Release.IsInstall: This is set to true if the current operation is an install.
Release.Revision: The revision number. It begins at 1, and increments with each helm upgrade.
Chart: The contents of the Chart.yaml. Thus, the chart version is obtainable as "Chart.Version" and the maint
Files: Files can be accessed using {{index .Files "file.name"}} or using the "{{.Files.Get name}}" or "{{.Fi
Capabilities: "({{.Capabilities.KubeVersion}}", Tiller "({{.Capabilities.TillerVersion}}", and the supported
{{.Files.Get config.ini}}
{{.Files.GetBytes}} useful for things like images
{{.Template.Name}}
{{.Template.BasePath}}
default value
//same
{{ .Values.storage | default "minio" }}
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 7/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
# same result
heritage: {{ quote .Release.Service }}
global variable
global:
app: MyWordPress
Includes a template called mytpl.tpl , then lowercases the result, then wraps that in double quotes
required function declares an entry for .Values.who is required, and will print an error message when that
entry is missing
The sha256sum function can be used together with the include function to ensure a deployments template
section is updated if another spec changes
kind: Deployment
spec:
template:
metadata:
annotations:
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 8/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
The annotation "helm.sh/resource-policy": keep instructs Tiller to skip this resource during a helm delete
operation
In the templates/ directory, any file that begins with an underscore(_) is not expected to output a
Kubernetes manifest file. So by convention, helper templates and partials are placed in a _helpers.tpl file.
Hooks
Read more
include these annotation inside hook yaml file, for e.g templates/post-install-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-weight": "-5"
Chart repository
Read more
Signing
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 9/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Read more
Test
Read more
Flow Control
If/Else
{{ if PIPELINE }}
# Do something
{{ else if OTHER PIPELINE }}
# Do something else
{{ else }}
# Default case
{{ end }}
data:
myvalue: "Hello World"
drink: {{ .Values.favorite.drink | default "tea" | quote }}
food: {{ .Values.favorite.food | upper | quote }}
{{- if eq .Values.favorite.drink "lemonade" }}
mug: true
{{- end }} # notice the "-" in the left, if will help eliminate newline before variable
With
with can allow you to set the current scope (.) to a particular object
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 10/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
data:
myvalue: "Hello World"
{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
{{- end }} # instead of writing ".Values.favorite.drink"
Inside of the restricted scope , you will not be able to access the other objects from the parent scope
Range
# predefined variable
pizzaToppings:
- mushrooms
- cheese
- peppers
- onions
toppings: |-
{{- range $i, $val := .Values.pizzaTopping }}
- {{ . | title | quote }} # upper first character, then quote
{{- end }}
sizes: |-
{{- range tuple "small" "medium" "large" }}
- {{ . }}
{{- end }} # make a quick list
Variables
It follows the form $name . Variables are assigned with a special assignment operator: :=
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 11/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
data:
myvalue: "Hello World"
{{- $relname := .Release.Name -}}
{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
release: {{ $relname }}
{{- end }}
#toppings: |-
# 0: mushrooms
# 1: cheese
# 2: peppers
# 3: onions
There is one variable that is always global - $ - this variable will always point to the root context
...
labels:
# Many helm templates would use `.` below, but that will not work,
# however `$` will work here
app: {{ template "fullname" $ }}
# I cannot reference .Chart.Name, but I can do $.Chart.Name
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 12/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Named Templates
template names are global
# _helpers.tpl
{{/* Generate basic labels */}}
{{- define "my_labels" }}
labels:
generator: helm
date: {{ now | htmlDate }}
version: {{ .Chart.Version }}
name: {{ .Chart.Name }}
{{- end }}
When a named template (created with define) is rendered, it will receive the scope passed in by the template
call.
# configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
{{- template "my_labels" . }} # Notice the final dot, it will pass the global scope inside template file. W
{{- include "my_labels" . | indent 2 }} # similar to "template" directive, have the ability to control ind
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 13/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
referable to use include over template . Because template is an action , and not a function , there is no
way to pass the output of a template call to other functions; the data is simply inserted inline .
data:
{{- $file := .Files }} # set variable
{{- range tuple "config1.toml" "config2.toml" "config3.toml" }} # create list
{{ . }}: |- # config file name
{{ $file.Get . }} # get file's content
{{- end }}
apiVersion: v1
kind: ConfigMap
metadata:
name: conf
data:
+{{ (.Files.Glob "foo/*").AsConfig | indent 2 }}
---
apiVersion: v1
kind: Secret
metadata:
name: very-secret
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 14/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
type: Opaque
data:
+{{ (.Files.Glob "bar/*").AsSecrets | indent 2 }}
+token: |-
+ {{ .Files.Get "config1.toml" | b64enc }}
YAML reference
# Force type
age: !!str 21
port: !!int "80"
another: value
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 15/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
kubernetes-cheatsheet.md
Kubernetes cheatsheet
Kubernetes cheatsheet
Getting Started
Sample yaml
Workflow
Physical components
Master
Node
Everything is an object - persistent entities
Namespaces
Labels
ClusterIP
Controller manager
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 16/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Kube-scheduler
Pod
Status
Probe
Pod priorities
Multi-Container Pods
Init containers
Lifecycle hooks
Quality of Service (QoS)
PodPreset
ReplicaSet
Deployments
ReplicationController
DaemonSet
StatefulSet
Job (batch/v1)
Cronjob
Horizontal pod autoscaler
Services
Volumes
Persistent volumes
Role-Based Access Control (RBAC)
Notes
Basic commands
jsonpath
Resource limit
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 17/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
CPU
Memory
Chapter 13. Integrating storage solutions and Kubernetes
Downward API
Labs
Guaranteed Scheduling For Critical Add-On Pods
Set command or arguments via env
Getting Started
Fault tolerance
Rollback
Auto-healing
Auto-scaling
Load-balancing
Isolation (sandbox)
Sample yaml
apiVersion: <>
kind: <>
metadata:
name: <>
labels:
...
annotations:
...
spec:
containers:
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 18/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
...
initContainers:
...
priorityClassName: <>
Workflow
(kube-scheduler, controller-manager, etcd) --443--> API Server
non-verified certificate
MITM
Solution:
set kubelet-certificate-authority
ssh tunneling
Physical components
Master
API Server (443)
kube-scheduler
controller-manager
cloud-controller-manager
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 19/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
kube-controller-manager
etcd
Node
Kubelet
Container Engine
CRI
The protocol which used to connect between Kubelet & container engine
Kube-proxy
names: client-given
UIDs: system-generated
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 20/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
auditable
Declarative object configuration (yaml + config files)
Live object configuration
Current object configuration file
Last-applied object configuration file
Node Capacity
---------------------------
| kube-reserved |
|-------------------------|
| system-reserved |
|-------------------------|
| eviction-threshold |
|-------------------------|
| |
| allocatable |
| (available for pods) |
| |
| |
---------------------------
Namespaces
Three pre-defined
default
kube-system
kube-public: auto-readable by all users
Nodes
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 21/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
PersistentVolumes
Namespaces
Labels
key / value
loose coupling via selectors
need not be unique
ClusterIP
Controller manager
ReplicaSet, deployment, daemonset, statefulSet
Actual state <-> desired state
reconciliation loop
Kube-scheduler
nodeSelector
Affinity & Anti-Affinity
Node
Steer pod to node
Pod
Steer pod towards or away from pods
Taints & tolerations (anti-affinity between node and pod!)
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 22/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
...
tolerations:
- key: "dev"
operator: "equal"
value: "env"
effect: NoSchedule
...
Pod
File system
Image
Associated Volumes
ordinary
persistent
Container
Hostname
Pod
Pod name
User-defined envs
Services
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 23/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Access with:
Symlink (important):
/etc/podinfo/labels
/etc/podinfo/annotations
Or:
volumes:
- name: podinfo
downwardAPI:
items:
- path: "labels"
fieldRef:
fieldPath: metadata.labels
- path: "annotations"
fieldRef:
fieldPath: metadata.annotations
Status
Pending
Running
Succeeded
Failed
Unknown
Probe
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 24/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Liveness
Failed? Restart policy applied
Readiness
Failed? Removed from service
Pod priorities
Multi-Container Pods
Init containers
Lifecycle hooks
PostStart
PreStop (blocking)
Handlers:
Exec
HTTP
...
spec:
containers:
lifecycle:
postStart:
exec:
command: <>
preStop:
http:
...
When Kubernetes creates a Pod it assigns one of these QoS classes to the Pod:
If a Container specifies its own memory limit, but does not specify a memory request, Kubernetes automatically
assigns a memory request that matches the limit. Similarly, if a Container specifies its own cpu limit, but does
not specify a cpu request, Kubernetes automatically assigns a cpu request that matches the limit.
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 26/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
PodPreset
You can use a podpreset object to inject information like secrets, volume mounts, and environment variables etc into
pods at creation time. This task shows some examples on using the PodPreset resource
apiVersion: settings.k8s.io/v1alpha1
kind: PodPreset
metadata:
name: allow-database
spec:
selector:
matchLabels:
role: frontend
env:
- name: DB_PORT
value: "6379"
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
emptyDir: {}
ReplicaSet
Features:
Components:
Pod template
Label of replicaSet
Number of replica
Deployments
versioning and rollback
advanced deployment
blue-green
canary
Update containers --> new replicaSet & new pods created --> old RS still exists --> reduced to zero
Update strategy
Recreate
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 28/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
ReplicationController
RC = ( RS + deployment ) before
Obsolete
DaemonSet
Ensure all nodes run a copy of pod
Cluster storage, log collection, node monitor ...
StatefulSet
Maintains a sticky identity
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 29/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Not interchangeable
Identifier maintains across any rescheduling
Limitation
Flow
Job (batch/v1)
Non-parallel jobs
Parallel jobs
Fixed completion count
job completes when number of completions reaches target
With work queue
requires coordination
Use spec.activeDeadlineSeconds to prevent infinite loop
Cronjob
Job should be idempotent
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 30/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Services
Logical set of backend pods + frontend
CluterIP
NodePort
LoadBalancer
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 31/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
ExternalName
Service discovery
spec.dnsPolicy
default
inherit node's name resolution
ClusterFirst
Any DNS query that does not match the configured cluster domain suffix, such as “www.kubernetes.io”, is
forwarded to the upstream nameserver inherited from the node
ClusterFirstWithHostNet
if host network = true
None (since k8s 1.9)
Allow custom dns server usage
Headless service
Volumes
Lifetime longer than any containers inside a pod.
4 types:
configMap
emptyDir
gitRepo
secret
store on RAM
hostPath
Persistent volumes
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 33/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
# name must match the spec fields below, and be in the form: <plural>.<group>
name: crontabs.stable.example.com
spec:
# group name to use for REST API: /apis/<group>/<version>
group: stable.example.com
# version name to use for REST API: /apis/<group>/<version>
version: v1
# either Namespaced or Cluster
scope: Namespaced
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
plural: crontabs
# singular name to be used as an alias on the CLI and for display
singular: crontab
# kind is normally the CamelCased singular type. Your resource manifests use this.
kind: CronTab
# shortNames allow shorter string to match your resource on the CLI
shortNames:
- ct
# categories is a list of grouped resources the custom resource belongs to.
categories:
- all
validation:
# openAPIV3Schema is the schema for validating custom objects.
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 34/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
openAPIV3Schema:
properties:
spec:
properties:
cronSpec:
type: string
pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
replicas:
type: integer
minimum: 1
maximum: 10
# subresources describes the subresources for custom resources.
subresources:
# status enables the status subresource.
status: {}
# scale enables the scale subresource.
scale:
# specReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Spec.Rep
specReplicasPath: .spec.replicas
# statusReplicasPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status
statusReplicasPath: .status.replicas
# labelSelectorPath defines the JSONPath inside of a custom resource that corresponds to Scale.Status.
labelSelectorPath: .status.labelSelector
Notes
Basic commands
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 35/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
# Set context
kubectl config set-context $(kubectl config current-context) --namespace=<namespace-name>
access dashboard
# bash
kubectl -n kube-system port-forward $(kubectl get pods -n kube-system -o wide | grep dashboard | awk '{print
# fish
kubectl -n kube-system port-forward (kubectl get pods -n kube-system -o wide | grep dashboard | awk '{print
jsonpath
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 36/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
From link
{
"kind": "List",
"items":[
{
"kind":"None",
"metadata":{"name":"127.0.0.1"},
"status":{
"capacity":{"cpu":"4"},
"addresses":[{"type": "LegacyHostIP", "address":"127.0.0.1"}]
}
},
{
"kind":"None",
"metadata":{"name":"127.0.0.2"},
"status":{
"capacity":{"cpu":"8"},
"addresses":[
{"type": "LegacyHostIP", "address":"127.0.0.2"},
{"type": "another", "address":"127.0.0.3"}
]
}
}
],
"users":[
{
"name": "myself",
"user": {}
},
{
"name": "e2e",
"user": {"username": "admin", "password": "secret"}
}
]
}
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 37/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
the current
@ {@} the same as input
object
recursive
.. {..name} 127.0.0.1 127.0.0.2 myself e2e
descent
[start:end subscript
{.users[0].name} myself
:step] operator
{.users[?
?() filter secret
(@.name=="e2e")].user.password}
quote
{range .items[*]}{.metadata.name}{'\t'}
'' interpreted 127.0.0.1 127.0.0.2
{end}
string
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 38/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Resource limit
CPU
The CPU resource is measured in cpu units. One cpu, in Kubernetes, is equivalent to:
1 AWS vCPU
1 GCP Core
1 Azure vCore
1 Hyperthread on a bare-metal Intel processor with Hyperthreading
Memory
The memory resource is measured in bytes. You can express memory as a plain integer or a fixed-point integer with
one of these suffixes: E, P, T, G, M, K, Ei, Pi, Ti, Gi, Mi, Ki. For example, the following represent approximately the same
value:
kind: Service
apiVersion: v1
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 39/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
metadata:
name: external-database
spec:
type: ExternalName
externalName: "database.company.com
kind: Service
apiVersion: v1
metadata:
name: external-ip-database
---
kind: Endpoints
apiVersion: v1
metadata:
name: external-ip-database
subsets:
- addresses:
- ip: 192.168.0.1
ports:
- port: 3306
Downward API
The following information is available to containers through environment variables and downwardAPI volumes:
metadata.labels - all of the pod’s labels, formatted as label-key="escaped-label-value" with one label per line
metadata.annotations - all of the pod’s annotations, formatted as annotation-key="escaped-annotation-value"
with one annotation per line
Labs
Marking pod as critical when using Rescheduler. To be considered critical, the pod has to:
Run in the kube-system namespace (configurable via flag)
Have the scheduler.alpha.kubernetes.io/critical-pod annotation set to empty string
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 41/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
The first one marks a pod a critical. The second one is required by Rescheduler algorithm.
Marking pod as critical when priorites are enabled. To be considered critical, the pod has to:
Run in the kube-system namespace (configurable via flag)
Have the priorityClass set as system-cluster-critical or system-node-critical , the latter being the
highest for entire cluster
scheduler.alpha.kubernetes.io/critical-pod annotation set to empty string(This will be deprecated too).
env:
- name: MESSAGE
value: "hello world"
command: ["/bin/echo"]
args: ["$(MESSAGE)"]
tools.md
Helm
helm chart unit test https://github.com/xchapter7x/hcunit?utm_sq=g92df5t58c
Container
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 42/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
AWS
SSO login: https://github.com/wnkz/aws-sso/blob/master/README.md
kind: Service
apiVersion: v1
metadata:
name: someService
annotations:
service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
service.beta.kubernetes.io/aws-load-balancer-access-log-enabled (true|false)
service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-name
service.beta.kubernetes.io/aws-load-balancer-access-log-s3-bucket-prefix
service.beta.kubernetes.io/aws-load-balancer-backend-protocol (http|https|ssl|tcp)
service.beta.kubernetes.io/aws-load-balancer-connection-draining-enabled (true|false)
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 43/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled (true|false)
service.beta.kubernetes.io/aws-load-balancer-internal: '0.0.0.0/0'
service.beta.kubernetes.io/aws-load-balancer-proxy-protocol: '*'
for i in (kpods | grep drone-agent | awk '{print $2}' ); echo $i ; kubectl logs --tail=10 $i; end
kubectl get sa <service-account-name> -o json | jq -r ".secrets[0].name" | xargs kubectl get secret -o json | jq -r ".data.token" | ba
# See https://github.com/stedolan/jq/issues/204#issuecomment-27089261
kubectl get sa <service-account-name> -o json | jq -r ".secrets[0].name" | xargs kubectl get secret -o json | jq '.data["ca.crt"]' | p
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 44/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Start minikube
<service-name>.<namespace>.svc.cluster.local
kubectl api-versions
TOKEN=$(kubectl describe secret $(kubectl get secrets | grep default-token | cut -f1 -d ' ' | head -1) | grep -E '^token' | cut -f2
-d':' | tr -d '\t')
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 45/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: "{{ template "fullname" . }}"
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: "{{ template "fullname" . }}"
type: Opaque
data:
{{- range $key, $value := .Values.secrets }}
{{ $key }}: {{ $value | b64enc | quote}}
{{- end }}
values.yaml:
secrets:
aws-access-key-id: ""
aws-secret-access-key: ""
env:
{{- range $key, $value := .Values.config }}
- name: {{ $key | upper | replace "-" "_" }}
value: {{ $value | quote }}
{{- end}}
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 46/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
Upgrade with setting new value and retain the old one:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{.Chart.Name}}-{{.Chart.Version}}"
app: "{{ template "fullname" . }}"
annotations:
checksum/config-map: {{ include (print $.Chart.Name "/templates/secret.yaml") . | sha256sum }}
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 47/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 48/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
sample deployment:
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 49/50
17/04/2020 #Helm #Kubernetes #cheatsheet, happy helming! · GitHub
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
Thanks
https://gist.github.com/tuannvm/4e1bcc993f683ee275ed36e67c30ac49 50/50