• Use kubie to simplify changes between kubernetes contexts and namespaces

    2 min read

    kubernetes kubectl context kubie

    On another post we talked about how to change kubernetes context using kubectl and there's another post for setting a default namespace for a given context. kubie is a tool that helps trying to make it easier

    17/03/2021

    Read more...
  • kubernetes: List available API using kubectl

    2 min read

    kubernetes list API version k3s

    With kubectl api-resources we can get the list of available objects, but the same object can be defined using different API versions, for example the Ingress object is different on v1beta1 compared to v1. Using kubectl api-versions we can get the list of all the available API versions on our kubernetes cluster

    16/03/2021

    Read more...
  • kubernetes: Get events across multiple objects

    4 min read

    kubernetes get events kubectl

    The most commonly used way to get events is by using kubectl describe on each object like this:

    $ kubectl describe pod pet2cattle-6597f8464d-hgxpp
    Name:         pet2cattle-6597f8464d-hgxpp
    (...)
    Events:
      Type     Reason     Age    From               Message
      ----     ------     ----   ----               -------
      Normal   Scheduled  3m47s  default-scheduler  Successfully assigned kube-system/pet2cattle-6597f8464d-hgxpp to scopuli.lolcathost.systemadmin.es
      Normal   Pulled     3m46s  kubelet            Container image "172.18.1.46:5000/p2c:3.44" already present on machine
      Normal   Created    3m46s  kubelet            Created container pet2cattle-sitemap
      Normal   Started    3m46s  kubelet            Started container pet2cattle-sitemap
      Normal   Pulled     3m41s  kubelet            Container image "172.18.1.46:5000/p2c:3.44" already present on machine
      Normal   Created    3m41s  kubelet            Created container pet2cattle-indexer
      Normal   Started    3m40s  kubelet            Started container pet2cattle-indexer
      Normal   Pulled     3m32s  kubelet            Container image "172.18.1.46:5000/p2c:3.44" already present on machine
      Normal   Created    3m32s  kubelet            Created container pet2cattle
      Normal   Started    3m31s  kubelet            Started container pet2cattle
      Warning  Unhealthy  3m26s  kubelet            Liveness probe failed: Get http://10.42.0.8:8000/: net/http: request canceled (Client.Timeout exceeded while awaiting headers)
    

    It's quite convenient when we are looking for events related to a given but becomes a pain if we need to see how the events are triggered on multiple objects.

    15/03/2021

    Read more...
  • kubernetes: Pods can be composed of multiple containers

    2 min read

    kubernetes multiple containers pod

    One common misunderstanding with kubernetes is mistakenly assume "a pod" really means "a container".

    A pod is the minimal unit we take into account in kubernetes but this does not mean that a pod is a container: A pod can be composed of several containers working together. We can easily see this on the READY column that are going to tell us for a given pod from how many containers it is composed:

    $ kubectl  get pods
    NAME                                     READY   STATUS      RESTARTS   AGE
    ampa-7dcbfd689f-59ghw                    2/2     Running     0          5d1h
    

    12/03/2021

    Read more...
  • Using terraform_remote_state for getting data from another terraform state

    2 min read

    terraform data remote state terraform_remote_state

    On terraform, besides returning some information to the user, returning data as output can be used as an input for terraform code that needs to use a resource created by another team.

    On the terraform code that creates the resource, we will have to set the variable and it's value:

    output endpoint {
        vpc_id = aws_vpc.databases.id
    }
    

    Then, on the code that uses this resource we will have to declare the tfstate as a data source using terraform_remote_state

    11/03/2021

    Read more...
  • The selector option can help us to select a subset of pods with kubectl

    2 min read

    kubernetes pod selector label

    On most kubectl command we will find the selector option for filtering pods based on it's labels. To use we just need to set the filter using the key=value format:

    $ kubectl get pods -l "app=spin"
    NAME                               READY   STATUS    RESTARTS   AGE
    spin-clouddriver-9899c9b54-nbjp6   1/1     Running   0          29h
    spin-deck-56ff48c587-lc75g         1/1     Running   0          29h
    spin-echo-7ccf545b48-b5n9l         1/1     Running   0          29h
    spin-front50-59bff89745-2f65h      1/1     Running   0          29h
    spin-gate-644c968b68-2q8nj         1/1     Running   0          29h
    spin-igor-6669794575-2cnb4         1/1     Running   0          29h
    spin-orca-795789b678-nqrk7         1/1     Running   0          29h
    spin-rosco-6c9879b69f-gdrfl        1/1     Running   0          29h
    

    10/03/2021

    Read more...
  • Enabling debug information on terraform using TF_LOG

    2 min read

    terraform TF_LOG debug

    Sometimes with terraform you might end up with some meaningless error that does not provide any clue what's going on. So instead or just trying to guess that have changed; we can enable some traces in terraform to try to make sense what's going on

    Error: AccessDenied: Access Denied
      status code: 403, request id: 8FCD12996B11F5F8, host id: xMF1Gs+VIEpxpk+1Og6UtchyT10K+mRWFe2IUZ8gqG13KbsRm0L8nRw8udzkqEVJagg8+RMpY3M=
    

    09/03/2021

    Read more...
  • terraform: Refresh null_resource when a variable changes

    2 min read

    terraform triggers null_resource local-exec

    When using local-exec with the null_resource we might need to be able to update the resources that gets created like this. Let's assume we have the following terraform code to apply Kustomize to a kubernetes cluster:

    resource "null_resource" "metrics-server" {
      provisioner "local-exec" {
        command = "kubectl apply -k 'https://github.com/jordiprats/django-ampa/deploy-${var.version}/'"
      }
    }
    

    Given this setup even though the var.version changed, the resource won't be updated if it was already applied

    08/03/2021

    Read more...
  • Setting secret into a environment variable

    2 min read

    kubernetes secret environment variable pod deployment

    Although it's not a best practice to feed secrets into environment variables it's still something that it is possible to do. Let's take a glance on how to do it

    05/03/2021

    Read more...
  • Relationship between Deployment and ReplicaSet in kubernetes

    3 min read

    kubernetes deployment ReplicaSet

    Although ReplicaSet's main purpose is to maintain a stable set of replica Pods, it's not a kubernetes object that is commonly created, at least not explicitly. But the replicas attribute on the Deployment object is actually related to this object

    04/03/2021

    Read more...

More recent...

Older content...

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