Skip to content

Instantly share code, notes, and snippets.

@fragaLY
Created December 27, 2021 11:28
Show Gist options
  • Save fragaLY/8ec3aa6bdc057704b8b479a8f2c81eb0 to your computer and use it in GitHub Desktop.
Save fragaLY/8ec3aa6bdc057704b8b479a8f2c81eb0 to your computer and use it in GitHub Desktop.
Working with Google Kubernetes Engine Secrets and ConfigMaps
apiVersion: v1
data:
airspeed: africanOrEuropean
meme: testAllTheThings
kind: ConfigMap
metadata:
name: sample3
namespace: default
selfLink: /api/v1/namespaces/default/configmaps/sample3
apiVersion: apps/v1
kind: Deployment
metadata:
name: pubsub
spec:
selector:
matchLabels:
app: pubsub
template:
metadata:
labels:
app: pubsub
spec:
volumes:
- name: google-cloud-key
secret:
secretName: pubsub-key
- name: config-3
configMap:
name: sample3
containers:
- name: subscriber
image: gcr.io/google-samples/pubsub-sample:v1
volumeMounts:
- name: google-cloud-key
mountPath: /var/secrets/google
- name: config-3
mountPath: /etc/config
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /var/secrets/google/key.json
- name: INSIGHTS
valueFrom:
configMapKeyRef:
name: sample3
key: meme
apiVersion: apps/v1
kind: Deployment
metadata:
name: pubsub
spec:
selector:
matchLabels:
app: pubsub
template:
metadata:
labels:
app: pubsub
spec:
volumes:
- name: google-cloud-key
secret:
secretName: pubsub-key
containers:
- name: subscriber
image: gcr.io/google-samples/pubsub-sample:v1
volumeMounts:
- name: google-cloud-key
mountPath: /var/secrets/google
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /var/secrets/google/key.json
apiVersion: apps/v1
kind: Deployment
metadata:
name: pubsub
spec:
selector:
matchLabels:
app: pubsub
template:
metadata:
labels:
app: pubsub
spec:
containers:
- name: subscriber
image: gcr.io/google-samples/pubsub-sample:v1
message2=world
foo=bar
meaningOfLife=42
#preset
export my_zone=us-central1-a
export my_cluster=standard-cluster-1
source <(kubectl completion bash)
export my_service_account=[MY-SERVICE-ACCOUNT-EMAIL]
#move on
gcloud container clusters create $my_cluster --num-nodes 2 --zone $my_zone --service-account=$my_service_account
gcloud container clusters get-credentials $my_cluster --zone $my_zone
export my_pubsub_topic=echo
export my_pubsub_subscription=echo-read
gcloud pubsub topics create $my_pubsub_topic
gcloud pubsub subscriptions create $my_pubsub_subscription --topic=$my_pubsub_topic
git clone https://github.com/GoogleCloudPlatform/training-data-analyst
ln -s ~/training-data-analyst/courses/ak8s/v1.1 ~/ak8s
cd ~/ak8s/Secrets/
kubectl apply -f pubsub.yaml
kubectl get pods -l app=pubsub
#create secrets
kubectl create secret generic pubsub-key > --from-file=key.json=$HOME/credentials.json
rm -rf ~/credentials.json
kubectl apply -f pubsub-secret.yaml
kubectl get pods -l app=pubsub
gcloud pubsub topics publish $my_pubsub_topic --message="Hello, world!"
kubectl logs -l app=pubsub
#create configmap
kubectl create configmap sample --from-literal=message=hello
kubectl describe configmaps sample
kubectl create configmap sample2 --from-file=sample2.properties
kubectl describe configmaps sample2
#use mounted volumes to consume ConfigMaps in containers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment