Skip to content

Instantly share code, notes, and snippets.

@neoakris
Last active September 16, 2022 17:27
Show Gist options
  • Save neoakris/29afd0bc1f91a5df0543c7c4c1463f92 to your computer and use it in GitHub Desktop.
Save neoakris/29afd0bc1f91a5df0543c7c4c1463f92 to your computer and use it in GitHub Desktop.
cat_generated_config_file.sh
tee original-managedcert.yaml << EOF
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: managed-cert
spec:
domains:
- example.test
EOF
# Note watch out for tab characters
# Above and below are not the same. Above will work because the spaces are spaces.
# Below will fail because the spaces are some kind of non standard space character or single space tab characters.
tee original-managedcert.yaml << EOF
apiVersion: networking.gke.io/v1
kind: ManagedCertificate
metadata:
name: managed-cert
spec:
domains:
- example.hidden-tab-characters
EOF
##########################################
cat << EOF | tee test.txt
multi
line
file
contents
EOF
##########################################################
# This syntax works with paths that require sudo #########
##########################################################
cat << EOF | sudo tee /etc/resolv.conf
nameserver none
EOF
##########################################################
##############################################################
# Useful for generating templatized YAML files ###############
##############################################################
export HTTPS_CRT=$(cat bigbang.dev.crt | base64 | tr -d '\n')
export HTTPS_KEY=$(cat bigbang.dev.key | base64 | tr -d '\n')
# Explanation of the above linux magic: the file is base64
# decoded, translate delete new lines cleans up some cruft
cat << EOF | tee ~/cert.yaml
apiVersion: v1
kind: Secret
metadata:
name: bb-demo-cert
namespace: zarf
data:
tls.crt: $HTTPS_CRT
tls.key: $HTTPS_KEY
type: kubernetes.io/tls
EOF
##############################################################
##############################################################
# Useful for generating kubectl patch files ##################
##############################################################
# Verification command to see pre-change value
alias k=kubectl
k get po -l=k8s-app=metrics-server -n=kube-system -o yaml | grep limits: -A 5
# Prep patch
cat << EOF > patch.yaml
kind: Deployment
apiVersion: apps/v1
spec:
template:
spec:
containers:
- name: metrics-server
resources:
limits:
memory: 200Mi
requests:
memory: 200Mi
EOF
# Apply patch
kubectl patch deployment metrics-server-v0.4.5 -n=kube-system --patch-file patch.yaml
# Confirm change
k get po -l=k8s-app=metrics-server -n=kube-system -o yaml | grep limits: -A 5
##############################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment