zoukankan      html  css  js  c++  java
  • CKAD练习题-Core Concepts

    Core Concepts (13%)

    Creating a Pod and Inspecting it

    1. Create the namespace ckad-prep.
    2. In the namespace ckad-prep create a new Pod named mypod with the image nginx:2.3.5. Expose the port 80.
    3. Identify the issue with creating the container. Write down the root cause of issue in a file named pod-error.txt.
    4. Change the image of the Pod to nginx:1.15.12.
    5. List the Pod and ensure that the container is running.
    6. Log into the container and run the ls command. Write down the output. Log out of the container.
    7. Retrieve the IP address of the Pod mypod.
    8. Run a temporary Pod using the image busybox, shell into it and run a wget command against the nginx Pod using port 80.
    9. Render the logs of Pod mypod.
    10. Delete the Pod and the namespace.

    Solution:

    First, create the namespace.

    $ kubectl create namespace ckad-prep

    Next, create the Pod in the new namespace.

    $ kubectl run mypod --image=nginx:2.3.5 --restart=Never --port=80 --namespace=ckad-prep
    pod/mypod created

    You will see that the image cannot be pulled as it doesn't exist with this tag.

    $ kubectl get pod -n ckad-prep
    NAME    READY   STATUS             RESTARTS   AGE
    mypod   0/1     ImagePullBackOff   0          1m

    The list of events can give you a deeper insight.

    $ kubectl describe pod -n ckad-prep
    ...
    Events:
      Type     Reason                 Age                 From                         Message
      ----     ------                 ----                ----                         -------
      Normal   Scheduled              3m3s                default-scheduler            Successfully assigned mypod to docker-for-desktop
      Normal   SuccessfulMountVolume  3m2s                kubelet, docker-for-desktop  MountVolume.SetUp succeeded for volume "default-token-jbcl6"
      Normal   Pulling                84s (x4 over 3m2s)  kubelet, docker-for-desktop  pulling image "nginx:2.3.5"
      Warning  Failed                 83s (x4 over 3m1s)  kubelet, docker-for-desktop  Failed to pull image "nginx:2.3.5": rpc error: code = Unknown desc = Error response from daemon: manifest for nginx:2.3.5 not found
      Warning  Failed                 83s (x4 over 3m1s)  kubelet, docker-for-desktop  Error: ErrImagePull
      Normal   BackOff                69s (x6 over 3m)    kubelet, docker-for-desktop  Back-off pulling image "nginx:2.3.5"
      Warning  Failed                 69s (x6 over 3m)    kubelet, docker-for-desktop  Error: ImagePullBackOff

    Go ahead and edit the existing Pod. Alternatively, you could also just use the kubectl set image pod mypod mypod=nginx --namespace=ckad-prep command.

    $ kubectl edit pod mypod --namespace=ckad-prep

    After setting an image that does exist, the Pod should render the status Running.

    $ kubectl get pod -n ckad-prep
    NAME    READY   STATUS    RESTARTS   AGE
    mypod   1/1     Running   0          14m

    You can shell into the container and run the ls command.

    $ kubectl exec mypod -it --namespace=ckad-prep  -- /bin/sh
    / # ls
    bin  boot  dev	etc  home  lib	lib64  media  mnt  opt	proc  root  run  sbin  srv  sys  tmp  usr  var
    / # exit

    Retrieve the IP address of the Pod with the -o wide command line option.

    $ kubectl get pods -o wide -n ckad-prep
    NAME    READY   STATUS    RESTARTS   AGE   IP               NODE
    mypod   1/1     Running   0          12m   192.168.60.149   docker-for-desktop

    Remember to use the --rm to create a temporary Pod.

    $ kubectl run busybox --image=busybox --rm -it --restart=Never -n ckad-prep -- /bin/sh
    If you don't see a command prompt, try pressing enter.
    / # wget -O- 192.168.60.149:80
    Connecting to 192.168.60.149:80 (192.168.60.149:80)
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
             35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    -                    100% |**********************************************************************|   612  0:00:00 ETA
    / # exit

    The logs of the Pod should show a single line indicating our request.

    $ kubectl logs mypod -n ckad-prep
    192.168.60.162 - - [17/May/2019:13:35:59 +0000] "GET / HTTP/1.1" 200 612 "-" "Wget" "-"

    Delete the Pod and namespace after you are done.

    $ kubectl delete pod mypod --namespace=ckad-prep
    pod "mypod" deleted
    $ kubectl delete namespace ckad-prep
    namespace "ckad-prep" deleted
  • 相关阅读:
    点击对应不同name的button,显示不同name的弹窗(弹窗功能)
    点击添加本地图片的前端效果制作
    巧用margin/padding的百分比值实现高度自适应(多用于占位,避免闪烁)
    移动端取消touch高亮效果
    手机网站的几点注意
    图片自动切换+链接
    使用DOM的方法获取所有li元素,然后使用jQuery()构造函数把它封装为jQuery对象
    使用jQuery匹配文档中所有的li元素,返回一个jQuery对象,然后通过数组下标的方式读取jQuery集合中第1个DOM元素,此时返回的是DOM对象,然后调用DOM属性innerHTML,读取该元素 包含的文本信息
    利用jQuery扩展接口为jQuery框架定义了两个自定义函数,然后调用这两个函数
    jQuery链式语法演示
  • 原文地址:https://www.cnblogs.com/peteremperor/p/12829981.html
Copyright © 2011-2022 走看看