Skip to content

Instantly share code, notes, and snippets.

@haf
Last active April 29, 2020 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haf/412666c5d230528e610f8353a15d9d79 to your computer and use it in GitHub Desktop.
Save haf/412666c5d230528e610f8353a15d9d79 to your computer and use it in GitHub Desktop.
My YAML snippet in vscode for kubernetes
{
// Place your snippets for yaml here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
"kind: PodDisruptionBudget": {
"prefix": "poddisruptionbudget",
"body": [
"apiVersion: policy/v1beta1",
"kind: PodDisruptionBudget",
"metadata:",
" name: ${1:name}",
"spec:",
" minAvailable: 1",
" selector:",
" matchLabels:",
" # REMEMBER TO UPDATE WITH kustomization.yaml changes!",
" app: ${1:name}",
" component: ${2:component}",
],
"description": "Create a new PodDisruptionBudget CRD instance"
},
"kind: VirtualService": {
"prefix": "virtualservice",
"body": [
"apiVersion: networking.istio.io/v1alpha3",
"kind: VirtualService",
"metadata:",
" name: $1 # alike your service",
"spec:",
" hosts:",
" - $2 # public domain names this service should be routed to for",
"",
" gateways:",
" - istio-system/$3 # your singleton gateway in the istio system",
" - mesh # if this is accessible via the istio mesh",
"",
" http:",
" - name: ${1:name}",
" route:",
" - destination:",
" host: ${4:service}.${5:namespace}.svc.cluster.local",
" port:",
" name: $0http",
],
"description": "Create a new Istio VirtualService"
},
"kind: HorizontalPodAutoscaler": {
"prefix": "horizontalpodautoscaler",
"body": [
"apiVersion: autoscaling/v2beta1",
"kind: HorizontalPodAutoscaler",
"metadata:",
" name: ${1:name}",
"",
"spec:",
" maxReplicas: 9",
" minReplicas: 3",
"",
" scaleTargetRef:",
" apiVersion: apps/v1",
" kind: Deployment",
" name: ${1:name}",
"",
" metrics:",
" - type: Resource",
" resource:",
" name: cpu",
" targetAverageUtilization: 80",
],
"description": "Create a new K8S Horizontal Pod Autoscaler"
},
"kind: ServiceAccount": {
"prefix": "serviceaccount",
"body": [
"apiVersion: v1",
"kind: ServiceAccount",
"metadata:",
" name: ${1:name}"
],
"description": "Create a new K8S service account"
},
"kind: Kustomization": {
"prefix": "kustomization",
"body": [
"apiVersion: kustomize.config.k8s.io/v1beta1",
"kind: Kustomization",
"",
"resources:",
"# TODO: change these:",
"- deployment.yaml",
"- configmap.yaml",
"- service.yaml",
"- virtualservice.yaml # for routing from the gateway",
"- hpa.yaml",
"- pdb.yaml",
"$0",
"",
"commonLabels:",
" app: ${1:app}",
" component: ${2:component}",
"",
"generatorOptions:",
" disableNameSuffixHash: true",
"",
"# TODO: remember your bitnami SealedSecrets, or else otherwise use:",
"#secretGenerator:",
"#- name: oauth2-proxy",
"# namespace: auth",
"# files:",
"# - oauth2-client-secret",
"# - oauth2-cookie-secret",
"# type: Opaque",
"",
"namespace: ${3:ns}"
],
"description": "Create the contents of a kustomization.yaml file"
},
"kind: Deployment": {
"prefix": "deployment",
"body": [
"kind: Deployment",
"apiVersion: apps/v1",
"metadata:",
" name: ${1:name}",
"",
" annotations:",
" sidecar.jaegertracing.io/inject: jaeger",
"",
"spec:",
" replicas: 3",
"",
" template:",
" spec:",
" affinity:",
" # https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#always-co-located-in-the-same-node",
" podAntiAffinity:",
" requiredDuringSchedulingIgnoredDuringExecution:",
" - labelSelector:",
" matchExpressions:",
" - key: app",
" operator: In",
" values:",
" - ${1:name} # see your kustomization.yaml file",
" topologyKey: kubernetes.io/hostname",
"",
" # https://blog.verygoodsecurity.com/posts/kubernetes-multi-az-deployments-using-pod-anti-affinity/",
" preferredDuringSchedulingIgnoredDuringExecution:",
" - podAffinityTerm:",
" labelSelector:",
" matchExpressions:",
" - key: app",
" operator: In",
" values:",
" - ${1:name} # see your kustomization.yaml file",
" topologyKey: failure-domain.beta.kubernetes.io/zone",
" weight: 100",
"",
" containers:",
" - name: ${1:name}",
" image: eu.gcr.io/${2:PROJECT_ID}/${1:name}",
"",
" ports:",
" - name: http",
" containerPort: 3000",
"",
" resources:",
" limits:",
" cpu: 1000m",
" memory: 500Mi",
" requests:",
" cpu: 10m",
" memory: 20Mi",
],
"description": "Create a new K8S deployment resource"
},
"kind: ConfigMap": {
"prefix": "configmap",
"body": [
"apiVersion: v1",
"kind: ConfigMap",
"metadata:",
" name: ${1:name}",
"",
"data:",
" ${1:name}.yaml: |",
" hello: world",
" this-is-yaml: true",
" routes:",
" - path: /a",
" destination: /b",
],
"description": "Create a new K8S ConfigMap resource"
},
"kind: Namespace": {
"prefix": "namespace",
"body": [
"apiVersion: v1",
"kind: Namespace",
"metadata:",
" name: ${1:name}",
" annotations:",
" istio-injection: enabled"
],
"description": "Create a new K8S Namespace resource"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment