informatica:sistemas_operativos:cursos:docker_a_fondo_introduccion_kubernetes
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| informatica:sistemas_operativos:cursos:docker_a_fondo_introduccion_kubernetes [2024/03/07 13:35] – [Resumen comandos] tempwin | informatica:sistemas_operativos:cursos:docker_a_fondo_introduccion_kubernetes [2024/03/07 15:49] (actual) – [Conceptos avanzados de Docker] tempwin | ||
|---|---|---|---|
| Línea 235: | Línea 235: | ||
| * Añadiendo una sentencia '' | * Añadiendo una sentencia '' | ||
| + | **Tienes un StatefulSet con 3 pods. El StatefulSet define una plantilla de PVC. Luego se desescala el StatefulSeta dos pods. ¿Qué ocurre con el PVC del tercer pod, con la configuración por defecto del StatefulSet? | ||
| + | |||
| + | * Se elimina automáticamente | ||
| + | * Se mantiene (**correcto**) | ||
| + | * El desescalado da error, ya que hay que eliminar manualmente el PVC antes | ||
| + | |||
| + | **Un desarrollador necesita conectarse a la BBDD de desarrollo, pero no conoce la cadena de conexión. Actualmente hay un pod que usa dicha cadena de conexión. El YAML del pod es como sigue:** | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Pod | ||
| + | metadata: | ||
| + | name: client | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: app | ||
| + | image: acme-org/ | ||
| + | env: | ||
| + | - name: DB_CONSTR | ||
| + | valueFrom: | ||
| + | - secretKeyRef: | ||
| + | name: db-data | ||
| + | key: constr | ||
| + | </ | ||
| + | |||
| + | **¿Qué le indicas al desarrollador para que pueda ver la cadena de conexión? | ||
| + | |||
| + | * Que pregunte al departamento de seguridad | ||
| + | * Que ejecute el comando '' | ||
| + | * Que ejecute el comando '' | ||
| + | * Que mire los logs del pod | ||
| + | * Que mire los logs del nodo | ||
| + | * Que abra una sesión interactiva con el pod y ejecute el comando '' | ||
| + | * '' | ||
| + | |||
| + | **¿Todos los pods de un StatefulSet tienen que tener la misma plantilla? | ||
| + | |||
| + | * Para nada, para crear pods idénticos se usa el Deployment | ||
| + | * Sí, porque un StatefulSet crea siempre pods idénticos (**correcto**) | ||
| + | * Sólo si no usan volúmenes persistentes | ||
| + | * El StatefulSet no crea pods, crea estados. | ||
| + | |||
| + | **¿Es posible configurar un StatefulSet para que elimine un PVC cuando el StatefulSet es desescalado? | ||
| + | |||
| + | * Sí, con la opción whenScaled a Delete (**correcto**) | ||
| + | * No, porque los PVCs son eliminados automáticamente cuando se elimina un pod | ||
| + | * No, solo puedes configurar que se borren los PVCs al eliminar el StatefulSet entero | ||
| + | * No, los PVCs siempre deben ser eliminados manualmente | ||
| + | |||
| + | **¿Puedes exponer MySQL a través de NodePort?** | ||
| + | |||
| + | * No, debes usar Ingress | ||
| + | * No, debes usar un servicio ExternalName | ||
| + | * No, debes usar un servicio LoadBalancer | ||
| + | * No, debes usar un servicio ClusterIP | ||
| + | * Sí (**correcto**) | ||
| ===== Resumen comandos ===== | ===== Resumen comandos ===== | ||
| Línea 312: | Línea 368: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | |||
| Listado de ficheros: | Listado de ficheros: | ||
| Línea 320: | Línea 375: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| Dockerfile: | Dockerfile: | ||
| Línea 406: | Línea 465: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| * '' | * '' | ||
| * '' | * '' | ||
| Línea 430: | Línea 493: | ||
| * '' | * '' | ||
| * '' | * '' | ||
| - | * '' | + | * '' |
| * '' | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| Creación de un pod de forma declarativa: | Creación de un pod de forma declarativa: | ||
| Línea 446: | Línea 526: | ||
| - image: dockercampusmvp/ | - image: dockercampusmvp/ | ||
| name: hello | name: hello | ||
| + | </ | ||
| + | |||
| + | Creación de pod de forma declarativa indicando variables de entorno: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Pod | ||
| + | metadata: | ||
| + | name: mypod | ||
| + | spec: | ||
| + | containers: | ||
| + | - image: imagenAUsar | ||
| + | name: ctr | ||
| + | env: | ||
| + | - name: FooVar | ||
| + | value: FooValue | ||
| + | - name: BarVar | ||
| + | value: BarValue | ||
| </ | </ | ||
| Línea 466: | Línea 564: | ||
| selector: | selector: | ||
| run: hello-declarative | run: hello-declarative | ||
| + | </ | ||
| + | |||
| + | ReplicaSet: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: apps/v1 | ||
| + | kind: ReplicaSet | ||
| + | metadata: | ||
| + | name: hello | ||
| + | spec: | ||
| + | replicas: 1 | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: hello | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: hello | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: hello | ||
| + | image: dockercampusmvp/ | ||
| + | </ | ||
| + | |||
| + | Deployment: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: hello | ||
| + | spec: | ||
| + | strategy: | ||
| + | type: rollingUpdate | ||
| + | rollingUpdate: | ||
| + | maxSurge: 1 # El valor por defecto es 25% | ||
| + | maxUnavailable: | ||
| + | replicas: 5 | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: hello | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: hello | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: hello | ||
| + | image: dockercampusmvp/ | ||
| + | </ | ||
| + | |||
| + | ConfigMap: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: ConfigMap | ||
| + | metadata: | ||
| + | name: staging | ||
| + | data: | ||
| + | api_url: https:// | ||
| + | environment_name: | ||
| + | </ | ||
| + | |||
| + | Config Map que contiene un fichero: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: ConfigMap | ||
| + | metadata: | ||
| + | name: config_staging | ||
| + | data: | ||
| + | config.json: | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Definición de volúmenes de pod: | ||
| + | |||
| + | <code yaml> | ||
| + | spec: | ||
| + | volumes: | ||
| + | - name: shared | ||
| + | emptyDir: {} | ||
| + | </ | ||
| + | |||
| + | Montaje de un Config Map en un contenedor de un pod: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: apps/v1 | ||
| + | kind: Deployment | ||
| + | metadata: | ||
| + | name: demovol | ||
| + | spec: | ||
| + | selector: | ||
| + | matchLabels: | ||
| + | app: demovol | ||
| + | template: | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: demovol | ||
| + | spec: | ||
| + | # Definimos el volumen | ||
| + | volumes: | ||
| + | - name: cfg | ||
| + | configMap: | ||
| + | name: config_staging | ||
| + | containers: | ||
| + | - name: demo | ||
| + | image: dockercampusmvp/ | ||
| + | # Montamos el volumen | ||
| + | volumeMounts: | ||
| + | - name: cfg # Nombre del volumen | ||
| + | mountPath: /app/config | ||
| + | </ | ||
| + | |||
| + | Secretos: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | data: | ||
| + | password: VmVyeUNvbXBsZXhQYXNzdzByZA== | ||
| + | kind: Secret | ||
| + | metadata: | ||
| + | name: mysecret | ||
| + | </ | ||
| + | |||
| + | Comando inicial de un contenedor: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Pod | ||
| + | metadata: | ||
| + | name: command | ||
| + | spec: | ||
| + | containers: | ||
| + | - name: main | ||
| + | image: alpine | ||
| + | command: | ||
| + | - /bin/ls | ||
| + | restartPolicy: | ||
| + | </ | ||
| + | |||
| + | Servicio NodePort: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Service | ||
| + | metadata: | ||
| + | name: hello | ||
| + | spec: | ||
| + | selector: | ||
| + | app: hello | ||
| + | ports: | ||
| + | - name: http | ||
| + | port: 8080 | ||
| + | targetPort: http | ||
| + | type: NodePort | ||
| + | </ | ||
| + | |||
| + | Servicio LoadBalancer: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: v1 | ||
| + | kind: Service | ||
| + | metadata: | ||
| + | name: hello | ||
| + | spec: | ||
| + | selector: | ||
| + | app: hello | ||
| + | ports: | ||
| + | - name: http | ||
| + | port: 8080 | ||
| + | targetPort: http | ||
| + | type: LoadBalancer | ||
| + | </ | ||
| + | |||
| + | |||
| + | Recurso Ingress: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: networking.k8s.io/ | ||
| + | kind: Ingress | ||
| + | metadata: | ||
| + | labels: | ||
| + | app: demo-ingress | ||
| + | name: demo-ingress | ||
| + | annotations: | ||
| + | ingress.kubernetes.io/ | ||
| + | spec: | ||
| + | rules: | ||
| + | - http: | ||
| + | paths: | ||
| + | - path: /api | ||
| + | pathType: ImplementationSpecific | ||
| + | backend: | ||
| + | service: | ||
| + | name: apisvc | ||
| + | port: | ||
| + | number: 80 | ||
| + | - path: /hello | ||
| + | pathType: ImplementationSpecific | ||
| + | backend: | ||
| + | service: | ||
| + | name: hellosvc | ||
| + | port: | ||
| + | number: 80 | ||
| + | </ | ||
| + | |||
| + | Recurso Ingress con hosts virtuales: | ||
| + | |||
| + | <code yaml> | ||
| + | apiVersion: networking.k8s.io/ | ||
| + | kind: Ingress | ||
| + | metadata: | ||
| + | name: hello-ingress | ||
| + | spec: | ||
| + | rules: | ||
| + | - host: dev.campusmvp.es | ||
| + | http: | ||
| + | paths: | ||
| + | - pathType: Prefix | ||
| + | path: "/ | ||
| + | backend: | ||
| + | service: | ||
| + | name: hellosvc | ||
| + | port: | ||
| + | name: http | ||
| </ | </ | ||
informatica/sistemas_operativos/cursos/docker_a_fondo_introduccion_kubernetes.1709814901.txt.gz · Última modificación: por tempwin
