Python: raise KeyError(key) from None

This:

will generate:

if the environment variable does not exist.

 

Instead use:

testing = os.environ.get('testing', 'False')

which lets you set a default.

 

aws_autoscaling_group – diffs didn’t match during apply. This is a bug with Terraform

happens when you have code like this:

Seems you can’t mix availability_zones and vpc_zone_identifier.

https://github.com/terraform-providers/terraform-provider-aws/issues/4801

CIDR to IPv4 converter

Handy converter: https://www.ipaddressguide.com/cidr

E.g. for the CIDR to IP Range using a CIDR Range of 10.10.20.0/26

means 64 IP addresses – the first being 0 and the last 33.

 

You can calculate this simply by adding up how many you need to get to 32 – i.e. 6.

Then 2^6 = 64.

So, the first would be 10.10.20.0 and the last would be 10.10.20.63.

 

Terraform: Error creating launch configuration: AlreadyExists: Launch Configuration by this name already exists

If you’re creating an ASG using an AWS Launch Configuration, you cannot use a name for the Launch Configuration.

The solution? Simply omit name from your launch configuration.

 

https://github.com/hashicorp/terraform/issues/3665

Launch Configurations cannot be updated after creation with the Amazon Web Service API.

https://www.terraform.io/docs/providers/aws/r/launch_configuration.html#using-with-autoscaling-groups

 

Install multiple versions of Python

 

Ignore the top link on Google which takes you a process of using pyenv. It’s not until you’ve spent several hours painstakingly following the instructions that you find out it’s for some shell I’ve never used called Fish.

Just do:

  1. brew install python2
  2. brew install python3
  3. then to use Python 2, use python2 and for Python 3, use python3

 


i.e. DON’T DO:

  1. use pyenv
  2. make sure brew is up to date: brew update && brew upgrade pyenv
  3. pyenv install 3.7.2
  4. pyenv install 2.7.14
  5. Set the global version with pyenv global 3.7.2
  6. Set local versions (e.g. for legacy projects) with pyenv local 2.7.14

 

Notes:

  • latest version of Python: https://www.python.org/downloads/
  • Blog post on pyenv: https://weknowinc.com/blog/running-multiple-python-versions-mac-osx

 

Problems:

ERROR: The Python zlib extension was not compiled. Missing the zlib?

brew install readline xz

did not work for me.

This worked though:

CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install -v 2.7.14

 

More:

https://github.com/pyenv/pyenv/wiki/common-build-problems

 

 

 

Versions

Let’s say you want to find out the version of some software. It’s a fucking mess. The options tend to be:

<software name> -v

<software name> --version

<software name> -V

<software name> version

<software name> -version

 

Unfortunately they all vary. E.g.

Python understands --version and -V.

Whereas Ansible only takes --version.

ssh only understands -V whereas PHP understands -v and --version.

Finally, Java stands by itself with the odd -version.

And I still haven’t figured out how you get ls to tell you its version on the Mac: https://unix.stackexchange.com/questions/415415/option-to-output-version

 

Here’s what uses what: 

-v

  • PHP

--version

  • Ansible
  • awk
  • PHP
  • Python 2.7 and 3.x
  • Terraform
  • zsh

-V

  • Python 2.7 and 3.x
  • ssh

version

  • kubectl
  • Terraform

-version

  • Java

 

Kubernetes Up & Running: Chapter 7

 

Code

 

In another terminal:

 

Now access the cluster with:

http://localhost:8080/

Note:

  • use http not https
  • If you get localhost refused to connect. then check original pod. E.g.
    • kubectl logs alpaca-prod-7f94b54866-dwwxg

which seems to indicate it’s successfully serving on 8080 locally.

So, the issue is with the code on Page 67. i.e. it should be:

kubectl port-forward $ALPACA_POD 8080:8080

 

DNS Resolver: http://localhost:8080/-/dns

with alpaca-prod

shows:

i.e. name of service: alpaca-prod

namespace: default

resource type: svc

base domain: cluster.local

Note: you could use:

  • alpaca-prod.default
  • alpaca-prod.default.svc.cluster.local.

 

Adding in a readinessProbe:

and restart port-forward (as the pods are recreated).

There should now be a Readiness Probe tab where you can make that pod fail / succeed /ready checks.

The pod with that IP address is destroyed after 3 fails and recreated after it succeeds.

k get endpoints alpaca-prod --watch

 

Now, after halting the port-forward and watch, we’ll look at NodePorts:

kubectl edit service alpaca-prod

and change

type: ClusterIP

to

type: NodePort

It immediately changes when you save. i.e.

kubectl describe service alpaca-prod

shows Type: NodePort

Note: if you misspell the Service type you’ll immediately be bounced back into the Editor with a couple of lines at the top indicating the problem. E.g.

 

 

https://github.com/shubheksha/Kubernetes-Up-and-Running-Notes/blob/master/Chapter7.md

See also Kubernetes: kubectl