• psql: Get the time it took a query to complete

    1 min read

    If you need to known the amount of time it took a query to complete on PostgreSQL, you can use the \timing function that psql has

    31/05/2021

    Read more...
  • terraform: Using dynamic blocks to conditionally set a block on a resource

    2 min read

    terraform dynamic blocks optional

    In the same way we can conditionally include a resource, we can also use for_each to conditionally include a nested block using terraform's dynamic blocks

    For example, if we want to add a variable that controls whether we should set this value:

    resource "helm_release" "spinnaker" {
      name  = "spinnaker"
    
      (...)
    
      set {
        name = "halyard.additionalScripts.data.enable_mptv2"
        type = "string"
        value = <<-EOF
          #!/bin/sh
          cat $0
          echo "custom mptv2"
          $HAL_COMMAND config features edit --managed-pipeline-templates-v2-ui true
        EOF
      }
    }
    

    28/05/2021

    Read more...
  • Terraform dynamic blocks

    3 min read

    terraform dynamic blocks

    When we have a resource that can have multiple nested blocks to be configured we can use dynamic blocks to configure it dynamically. A perfect example is a SecurityGroup that can have multiple ingress and egress rules to be able to allow traffic. Let's use the following aws_security_group resource definition as a starting point:

    resource "aws_security_group" "demo_sg" {
      name = "demo_sg"
      description = "pet2cattle demo SG with dynamic blocks"
      vpc_id = aws_vpc.main.id
    
      ingress {
        from_port        = 443
        to_port          = 443
        protocol         = "tcp"
        cidr_blocks      = [aws_vpc.main.cidr_block]
      }
    
      egress {
        from_port        = 0
        to_port          = 0
        protocol         = "-1"
        cidr_blocks      = ["0.0.0.0/0"]
      }
    }
    

    27/05/2021

    Read more...
  • Auto-upgrade k3s using the system-upgrade-controller

    3 min read

    k3s system-upgrade-controller

    A kubernetes cluster can get outdated pretty soon since Kubernetes keeps evolving at every release. If we have a k3s cluster we can use the system-upgrade-controller for automatically handling the upgrades. Let's take a look on how to configure it

    26/05/2021

    Read more...
  • kubernetes: Rollback a deployment update

    2 min read

    kubectl rolling update history undo

    When performing rolling updates we can see it's history using kubectl rollout history:

    $ kubectl rollout history deploy pet2cattle
    deployment.apps/pet2cattle 
    REVISION  CHANGE-CAUSE
    100       <none>
    101       <none>
    102       <none>
    103       <none>
    104       <none>
    105       <none>
    106       <none>
    107       <none>
    109       kubectl scale deployment/pet2cattle --replicas=2 --record=true
    110       kubectl scale deployment/pet2cattle --replicas=5 --record=true
    111       kubectl scale deployment/pet2cattle --replicas=1 --record=true
    

    If have any problem with the update we can undo and update using kubectl rollout undo

    25/05/2021

    Read more...
  • kubernetes: Mount an existing EBS volume to a pod

    2 min read

    If you have an existing EBS volume that you want to use on your EKS cluster, or you don't want to let Kubernetes to manage your volumes, you can use awsElasticBlockStore to link an existing EBS volume to a PersistentVolume or use it directly as a volume on a pod spec:

    24/05/2021

    Read more...
  • How to generate a self-signed certificate using OpenSSL

    2 min read

    Using openssl we can create a self-signed using a non interactive command suitable for automation if we give all the information at once such as the CN, and the days to expire

    21/05/2021

    Read more...
  • terraform: one() function to retrieve the only element of a list

    1 min read

    terraform one function terraform 0.15

    On the terraform 0.15 CHANGELOG we can see that they have added the one function. This function is intended to simplify existing code, improving it's readability and further smoothen the terraform learning curve

    20/05/2021

    Read more...
  • Difference between git reset: soft vs hard

    1 min read

    To be able to partially apply commits to other branches some times comes handy to use git reset together with git stash.

    With git reset we will be able to modify how the changes are stored on the repository. Let's see the differences between git reset --soft and git reset --hard.

    19/05/2021

    Read more...
  • Keeping record of the change cause using the --record flag

    3 min read

    kubectl rolling update history change-cause

    On Kubernetes, when we update objects such as a deployment or a daemonset we can check it's rollout history using kubectl rollout history:

    $ kubectl rollout history deploy pet2cattle
    deployment.apps/pet2cattle 
    REVISION  CHANGE-CAUSE
    21        <none>
    22        <none>
    23        <none>
    24        <none>
    26        <none>
    28        <none>
    29        <none>
    30        <none>
    32        <none>
    33        <none>
    34        <none>
    

    By default we won't be able to see a change cause, but we can fill this gap by setting the command that triggered the update adding the --record flag as follows:

    $ kubectl scale deployment/pet2cattle --replicas 2 --record
    deployment.apps/pet2cattle scaled
    

    18/05/2021

    Read more...

Older content...

From pet to cattle
Treat your kubernetes clusters like cattle, not pets