I do a bunch of work with Kubernetes (‘K8S’), building tools so researchers can do repeatable, scalable research using containers. To do so I had to figure out a bunch of useful commands for manipulating pods (containers), including deploying them, debugging, and host management. I started with the K8S cheatsheet and went from there.
We’ll use an example application that runs using web servers, database servers, and has a simple logging and monitoring setup.
host1
, host2
, host3
, etc.Let’s work with configmaps, ‘web-config’
List all configmaps
kutectl get configmap
Find one configmap
kutectl get configmap | grep web
See the details about a configmap
kubectl describe configmap web-config
Create a configmap from a file
kubectl create configmap web-config --from-file=/home/dnambi/deploy/web-configs/config.json
Create a configmap from a folder
kubectl create configmap web-config --from-file=/home/dnambi/deploy/web-configs/
Delete a configmap
kubectl delete configmap web-config
Let’s play with a secret, db-secret
Create secrets from a file
kubectl create secret generic db-secret --from-file=./username.txt --from-file=./password.txt
Create secrets from key-value pairs
kubectl create secret generic db-secret --from-literal=username='my-app' --from-literal=password='39528$vdg7Jb'
List all secrets
kubectl get secrets
Find all secrets with db in the name
kubectl get secrets | grep db
See the details about a secret
kubectl get secret db-secret -o yaml
Delete a secret
kubectl delete secret db-secret
kubectl create secret docker-registry regcred
--docker-server=<your-registry-server>
--docker-username=<your-name>
--docker-password=<your-pword> --docker-email=<your-email>
Find pod with one configmap DEVNFIXME Find pod that uses a service DEVNFIXME
List all pods
kubectl get pods
Find a pod named ‘logging’
kubectl get pods | grep logging
Find a pod that uses a particular configmap, ‘nginx-config’
kubectl get pods -o json
| jq '.items[].spec.containers[].env[]?.valueFrom.ConfigMapKeyRef.name'
| grep nginx | sort | uniq
Find all pods used for a particular service, ‘web-https’
kubectl get pods -l app=web-https
See the details about a pod, web-1
kubectl describe pods web-1
Delete a pod, web-2
kubectl delete pods web-2
See all services
kubectl get svc
Find one service, ‘web-https’
kubectl get svc | grep web
Find out the info about one service
kubectl describe svc web-https
Delete a service, ‘web-https’
kubectl delete svc web-https
See the details about a VM (‘node’, in K8S parlance).
List all nodes
kubectl get nodes
Find one node, ‘smallhost’
kubectl get nodes | grep smallhost
Find the details about one node, ‘smallhost’
kubectl describe nodes smallhost
Isolate a node for maintenance, ‘oldnode’
kubectl cordon oldnode
kubectl drain oldnode --ignore-daemonsets
Put a cordoned node back into service
kubectl uncordon oldnode
No piece of code is ever done. I’ll add more snippets over time. Happy coding!
Permalink2019 is over. As is my tradition, I use the New Year to look back, reflect, and learn lessons. I’ve always been a student; I see life as a series of puzzles to solve, and lessons to learn.
2019 was a year of growth. Large parts of my life were stable, so I had the buffer to grow in ways I wanted.
Here’s a few of the things I did and learned over the year…
My work went through some interesting changes this year.
All that said, I loved where I work. I have faith in the work I do, and the impact it can have on the world. (Interested? We’re hiring!).
When I look back upon the lessons of 2019, patterns emerge.
2019 is over. With any luck, I will use the lessons from this last year to grow in this next one.
2020 begins.
Permalink