Skip to content

DeamonSets

Desarrollo del tema

La presente guía aborda la creacion y uso del componente DeamonSet de Kubernetes.

Laboratorio: DeamonSets

Descripción

La presente guía aborda la creacion y uso del componente DeamonSet de Kubernetes.

Objetivos

  • Crear un DeamonSet a partir de un archivo YAML
  • Administrar un DeamonSet con sus diferentes operaciones

Antes de comenzar

  • Contar con el acceso al ambiente de laboratorio

Conexión hacia cluster

  1. Ingrese al cluster asignado con las credenciales proporcionadas

  2. Obtenga el archivo kubeconfig posicionando sobre la carpeta a trabajar y cambiando su nombre a config

    mv /path/to/kubeconfig ~/.kube/config
    

  3. Configure la variable KUBECONFIG

    export KUBECONFIG=~/.kube/config
    

  4. Verifique el acceso mediante comandos

    kubectl get namespaces
    kubectl config set-context --current --namespace=userx
    

Inicio de laboratorio

  1. Cree un archivo llamado daemonset.yaml con el siguiente contenido:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: prometheus-daemonset
      namespace: userx
      labels:
        app: prometheus-daemonset
    spec:
      selector:
        matchLabels:
          app: prometheus-daemonset
      template:
        metadata:
          labels:
            app: prometheus-daemonset
    

  2. Agregue el bloque de spec en spec.template con un bloque de containers

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: prometheus-daemonset
      namespace: userx
      labels:
        app: prometheus-daemonset
    spec:
      selector:
        matchLabels:
          app: prometheus-daemonset
      template:
        metadata:
          labels:
            app: prometheus-daemonset
        spec:
            containers:
    

  3. Agregue al bloque de containers una lista de un contenedor de nombre prometheus y la imagen prom/node-exporter

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: prometheus-daemonset
      namespace: userx
      labels:
        app: prometheus-daemonset
    spec:
      selector:
        matchLabels:
          app: prometheus-daemonset
      template:
        metadata:
          labels:
            app: prometheus-daemonset
        spec:
          containers:
            - name: prometheus
              image: prom/node-exporter
              ports:
                - containerPort: 80
    

  4. Valide la sintaxis

    yq e daemonset.yaml
    

  5. Levante el recurso

    kubectl apply -f daemonset.yaml
    

  6. Revise los daemonsets en el namespace

    kubectl get daemonsets
    

  7. Obtenga información del daemonset prometheus-daemonset

    kubectl describe daemonset prometheus-daemonset
    

  8. Revise los pods en el namespace

    kubectl get pods
    

  9. Revise la inforamción del pod

    # Cambiar nombre-pod por el nombre real del Pod
    kubectl describe pod nombre-pod
    

  10. Limpie el ambiente

    kubectl delete -f daemonset.yaml