zoukankan      html  css  js  c++  java
  • ckad练习题- multi-container-pods

    Multi-Container Pods (10%)

    Implementing the Adapter Pattern

    The adapter pattern helps with providing a simplified, homogenized view of an application running within a container. For example, we could stand up another container that unifies the log output of the application container. As a result, other monitoring tools can rely on a standardized view of the log output without having to transform it into an expected format.

    1. Create a new Pod in a YAML file named adapter.yaml. The Pod declares two containers. The container app uses the image busybox and runs the command while true; do echo "$(date) | $(du -sh ~)" >> /var/logs/diskspace.txt; sleep 5; done;. The adapter container transformer uses the image busybox and runs the command sleep 20; while true; do while read LINE; do echo "$LINE" | cut -f2 -d"|" >> $(date +%Y-%m-%d-%H-%M-%S)-transformed.txt; done < /var/logs/diskspace.txt; sleep 20; done; to strip the log output off the date for later consumption my a monitoring tool. Be aware that the logic does not handle corner cases (e.g. automatically deleting old entries) and would look different in production systems.
    2. Before creating the Pod, define an emptyDir volume. Mount the volume in both containers with the path /var/logs.
    3. Create the Pod, log into the container transformer. The current directory should continuously write a new file every 20 seconds.

    Solution:

    kubectl run adapter --image=busybox --restart=Never -o yaml --dry-run -- /bin/sh -c 'while true; do echo "$(date) | $(du -sh ~)" >> /var/logs/diskspace.txt; sleep 5; done;' > adapter.yaml

    The final Pod YAML file should look something like this:

    apiVersion: v1
    kind: Pod
    metadata:
      creationTimestamp: null
      name: adapter
    spec:
      volumes:
        - name: config-volume
          emptyDir: {}
      containers:
      - args:
        - /bin/sh
        - -c
        - 'while true; do echo "$(date) | $(du -sh ~)" >> /var/logs/diskspace.txt; sleep 5; done;'
        image: busybox
        name: app
        volumeMounts:
          - name: config-volume
            mountPath: /var/logs
        resources: {}
      - image: busybox
        name: transformer
        args:
        - /bin/sh
        - -c
        - 'sleep 20; while true; do while read LINE; do echo "$LINE" | cut -f2 -d"|" >> $(date +%Y-%m-%d-%H-%M-%S)-transformed.txt; done < /var/logs/diskspace.txt; sleep 20; done;'
        volumeMounts:
          - name: config-volume
            mountPath: /var/logs
      dnsPolicy: ClusterFirst
      restartPolicy: Never
    status: {}
    kubectl exec adapter --container=transformer -it -- /bin/sh
    / # ls -l
    -rw-r--r--    1 root     root           205 May 12 20:43 2019-05-12-20-43-32-transformed.txt
    -rw-r--r--    1 root     root           369 May 12 20:43 2019-05-12-20-43-52-transformed.txt
    ...
    / # cat 2019-05-12-20-43-52-transformed.txt
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
     4.0K    /root
    / # exit
  • 相关阅读:
    JS中字符串的true转化为boolean类型的true
    jquery select change下拉框选项变化判断选中值
    C# 使用 NPOI 库读写 Excel 文件
    通过微信分享链接,后面被加上from=singlemessage&isappinstalled=1导致网页打不开
    C# 中使用 ThoughtWorks.QRCode.dll 生成指定尺寸和边框宽度的二维码
    除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图、内联函数、派生表、子查询和公用表表达式中无效
    SQL查询语句如何能够让指定的记录排在最后
    搞懂 JavaScript 继承原理
    基于Socket通讯(C#)和WebSocket协议(net)编写的两种聊天功能(文末附源码下载地址)
    SqlServer 使用sys.dm_tran_locks处理死锁问题
  • 原文地址:https://www.cnblogs.com/peteremperor/p/12830764.html
Copyright © 2011-2022 走看看