• 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
  • 相关阅读:
    iis重写模块实现程序自动二级域名,微软提供的URL重写2.0版本适用IIS以上
    借助微软提供的url重写类库URLRewriter.dll(1.0)实现程序自动二级域名,域名需要泛解析
    AspNetPager控件报错误: Syntax error, unrecognized expression: input#ctl00$ContentPlaceHolder1$Aspnetpager1_input问题解决[摘]
    精准定位才能赢得人心
    IIS7.5打开GZip压缩,同时启用GZip压缩JS/CSS文件的设置方法[bubuko.com]
    c#变量缺少using引用,如何快速加上using,加Using的快捷键[bubuko.com]
    chart.js插件生成折线图时数据普遍较大时Y轴数据不从0开始的解决办法[bubuko.com]
    要用于尝试,广东移动间接实现“流量不清零”[bubuko.com]
    jquery中ajax在firefox浏览器下“object XMLDocument”返回结果的解决办法
    mvc中Url.RouteUrl或者Html.RouteLink实现灵活超链接,使href的值随路由名称或配置的改变而改变[bubuko.com]
  • 原文地址:https://www.cnblogs.com/peteremperor/p/12829981.html
Copyright © 2020-2023  润新知