Brain dump of various kubernetes/kubectl
things before I forget them all.
I’m coming from the deploying analytics side, not the person who sets
up kubernetes side, so this will be a list of useful day 1 type stuff
for anyone who is learning kubernetes practically via deployments
and kubectl
.
Understand
service
- something with an IP/hostname you want to hit, e.g. a RESTful front end.deployment
- powers aservice
by specifying things like number of instances, and how ports are shuffled.pods
- basic atomic-ish unit that make up a deployment. An instance.
Suppose you want to stand up your RESTful analytic with 8 instances,
available at foo.internal.com
. Start with a service, then a deployment.
Pods come via the deployment.
kubectl
pacman -S kubectl
Get config file from ops-type person. Put or link in
~/.kube/config
, then
kubectl config show
to make sure you’re running with the correct one.
Change contexts, if needed, for various projects.
Basic commands
Pods
kubectl get pods
kubectl delete pod ...
You can delete a pod to have K8s immediately kick another one off, useful for getting info about why things aren’t working
Logs
kubectl logs pod-name
kubectl logs pod-name --previous
Get logs, or see why app crashed before via --previous
. Anything else,
you probably need some log aggregation service (Helm/fluentd?)
Services
kubectl deploy -f ./service.yaml
kubectl get services
Deploy services, which are sort of the interface between pods/containers and the rest of the cluster (and outside world).
Deployments
kubectl deploy -f ./deployment.yaml
kubectl delete deployment your-deployment
Deployments power services by specifying instances and memory, ports, docker images, etc.
Interaction outside cluster
kubectl port-forward services/your-service 8080:8080
Test whether or not your API/service/deployments actually work.
Next up: how Terraform does all this for you.