Unit Tests vs Integration Tests

Integration tests reveal if a feature is working or not but aren’t much use locating the problem.

Unit tests tell you if a single piece of code functions as expected.

 

https://stackoverflow.com/questions/5357601/whats-the-difference-between-unit-tests-and-integration-tests

and

https://stackoverflow.com/questions/10752/what-is-the-difference-between-integration-and-unit-tests

AWS Lambda

Disabling a Lambda function should be easier.

It should be a clear UI control in the Lambda > Functions dashboard.

Which it is except you have to click on the Trigger (e.g. CloudWatch Events), then scroll down and hit the Enabled / Disabled toggle switch next to the function name there.

Terraform Interpolation Syntax

Conditionals

Interpolations can contain conditionals. E.g.

using ternary operation:

i.e. if var.env == "production"

then subnet = var.prod_subnet

else subnet = var.dev_subnet

 

https://www.terraform.io/docs/configuration/interpolation.html#conditionals

Kubernetes: Labels vs Annotations

What’s the difference between a Label and an Annotation?

Labels contain identifying information and used by selector queries. They are used by Kubernetes internally so, for performance reasons, there are limits on the size of labels (63 characters or less).

https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/

 

Annotations are used for non-identifying information, especially large and/or structured/unstructured data.

https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/

 

https://vsupalov.com/kubernetes-labels-annotations-difference/

Kubernetes Up & Running: Chapter 4

Common kubectl commands

Namespace and Contexts

 

Note: to list namespaces, see Kubernetes: Namespaces

 

Page 34

kubectl get pods

Note -o wide gives more information.

kubectl describe pod <pod id>

 

Page 35

kubectl label pods <pod id> color=green

Show labels:

kubectl get pods --show-labels

Remove label:

kubectl label pods bar color-

Note: the command in the book does not work:

kubectl label pods bar -color

giving:

unknown shorthand flag: 'c' in -color

https://stackoverflow.com/questions/54011581/kubernetes-remove-label-unknown-shorthand-flag-c-in-color

 

Copy-and-paste: https://github.com/rusrushal13/Kubernetes-Up-and-Running/blob/master/Chapter4.md

Docker swarm

What is Docker swarm used for?

This SO post is pretty useful (albeit by a Kubernetes guy):

https://stackoverflow.com/questions/27640633/docker-swarm-kubernetes-mesos-core-os-fleet

TLDR

Swarm is an effort by Docker to extend the existing Docker API to make a cluster of machines look like a single Docker API. Fundamentally, our experience at Google and elsewhere indicates that the node API is insufficient for a cluster API. You can see a bunch of discussion on this here: https://github.com/docker/docker/pull/8859 and here: https://github.com/docker/docker/issues/8781

docker: automatically restart a container

Say you need to restart a VM or restart Docker. How do you restart a container?

E.g. you have:

then restarting Docker (e.g. on the Mac you can click the Docker icon in the toolbar and select Docker > Restart) you get:

whilst Docker is restarting and:

after the restart (i.e. no containers).

 

You can use --restart always

docker container run --restart always -d <image id> sleep 1d

to restart after a docker reboot.

 

This https://docs.docker.com/config/containers/start-containers-automatically/

says

See also https://docs.docker.com/config/containers/live-restore/#enable-live-restore

 

More on Restart Policies

There are 4 restart policies: no, on-failure, unless-stopped, always.

no is the default. i.e. don’t restart if a container stops.

The others are:

always

We’ve seen this before. E.g. let’s say we have a script:

Note: exit 1 indicates an error (exit 0 would indicate success).

which we use as follows:

 

We can build and run with:

This will exit.

To restart with always restart policy use:

docker container run --restart always -d testing_restarts

Now, when it crashes, under docker ps you’ll see:

 

on-failure

Here we can restart a container if it exits with a non-zero exit code. We can also specify a number of retries. E.g.

--restart on-failure:3

docker container run --restart on-failure:3 -d testing_restarts

Notes

  • the container will not restart if you do a docker stop <container id>
  • the container (and oddly even any containers that have stopped as a result of completing the on-failure number of retries – although only the first time the daemon was restarted) WILL restart if you restart the docker daemon

 

unless-stopped

Behaves the same as always except if a container is stopped.

Note: if you manually stop a container its restart policy is ignored until the Docker daemon restarts.

https://docs.docker.com/config/containers/start-containers-automatically/#restart-policy-details

 

Ensuring Containers Are Always Running with Docker’s Restart Policy

 

Live Restore

Lets you keep containers alive when the daemon becomes unavailable,.

https://docs.docker.com/config/containers/live-restore/#enable-live-restore

However, doing this on my installation of Docker gave:

because I was running a swarm service.

More: https://docs.docker.com/config/containers/live-restore/#live-restore-and-swarm-mode

I had to restore to Factory Defaults which means signing in to cloud.docker.com again.