Tips

Best Practices

Everything is Code

Advantages:

  • Copy paste! Easily take concepts from one project and use them in another
  • Source control. See who changed what why.
  • Rebuilding. If you have everything in source control, it becomes way easier to rebuild in case of a disaster.
  • Editing. You know what computers are really good at? Manipulating text. Take advantage of that by expressing everything as text.

And by everything, I mean EVERYTHING that you possibly can. Jenkins jobs, server configuration, Spinnaker pipelines. All of these things can be expressed in text form.

JVM

  • Don’t run JVM processes in a memory constrained environment. You will be met with no end of troubles with OutOfMemoryErrors out the wazoo unless you are very knowledgable and careful. Which most of us are not.
  • The JVM is great if your application is allowed to consume the memory of the entire server. But it does not like to share…

Terms

Kubernetes Terms

  • k8s - kubernetes
  • daemon set - each instance in the k8s cluster runs an image
  • deployment - similar to spinnaker cluster
  • jobs - containers that will terminate themselves
  • pods - instances
  • replica sets - similar to spinnaker server group (deployments recommended instead)
  • services - load balancers
  • persistent volume claims - when a persistent volume is attached to a pod
  • stateful sets - like deployments, but each instance has a unique identifier (even though they are all formed from the same image)

Helpful Commands

Docker commands

docker ps - list containers

docker run -d -p 8080:8888 IMAGE_NAME - Run a container, binding local port 8080 to container port 8888

docker run -it IMAGE_NAME /bin/bash - Go to bash shell of a new container

docker exec -it CONTAINER_NAME /bin/bash - Go to bash shell of a running container

SSH

Port Forwarding

ssh -L <local_port>:localhost:<remote_port> <remote_host>

Kubernetes

Kubernetes config files

Extracting a context

kubectl config use-context $CONTEXTNAME
kubectl config view --flatten --minify > $FILENAME

Merging context files

KUBECONFIG=$FILEPATH1:$FILEPATH2 kubectl config view --flatten > $MERGEDFILENAME

Long-lived pods

apiVersion: v1
kind: Pod
metadata:
  name: testclient
  namespace: default
spec:
  containers:
  - name: python
    image: python:3.7
    command:
      - sh
      - -c
      - "exec tail -f /dev/null"

Nginx

Disable caching

location / {
    expires 0;
    add_header "Cache-Control" "no-cache, no-store, must-revalidate";
}

Scripts

git fixup

This will take any changes to files and wrap them back up into the previous commit

#!/bin/sh
git commit -a --fixup HEAD
git rebase -i --autosquash HEAD~2