Task weight: 4%

Use context: kubectl config use-context k8s-c1-H

Do the following in Namespace default. Create a single Pod named ready-if-service-ready of image nginx:1.16.1-alpine. Configure a LivenessProbe which simply executes command true. Also configure a ReadinessProbe which does check if the url http://service-am-i-ready:80 is reachable, you can use wget -T2 -O- http://service-am-i-ready:80 for this. Start the Pod and confirm it isn't ready because of the ReadinessProbe.

Create a second Pod named am-i-ready of image nginx:1.16.1-alpine with label id: cross-server-ready. The already existing Service service-am-i-ready should now have that second Pod as endpoint.

Now the first Pod should be in ready state, confirm that.


译文:

在默认命名空间中执行以下操作。 创建名为 ready-if-service-ready 的单个 Pod,镜像为 nginx:1.16.1-alpine。 配置一个只执行命令 true 的 LivenessProbe。 还要配置一个 ReadinessProbe,它会检查 url http://service-am-i-ready:80 是否可达,您可以为此使用 wget -T2 -O- http://service-am-i-ready:80 . 启动 Pod 并确认它因 ReadinessProbe 而未就绪。

创建第二个名为 am-i-ready 的 Pod,镜像为 nginx:1.16.1-alpine,标签 id: cross-server-ready。 已经存在的服务 service-am-i-ready 现在应该将第二个 Pod 作为端点。

现在第一个 Pod 应该处于就绪状态,确认一下。


解答:

创建pod文件

k run ready-if-service-ready --image=nginx:1.16.1-alpine $do > 4_pod1.yaml
vim 4_pod1.yaml

4_pod1.yaml

# 4_pod1.yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: ready-if-service-ready
  name: ready-if-service-ready
spec:
  containers:
  - image: nginx:1.16.1-alpine
    name: ready-if-service-ready
    resources: {}
    livenessProbe:                                      # add from here
      exec:
        command:
        - 'true'
    readinessProbe:
      exec:
        command:
        - sh
        - -c
        - 'wget -T2 -O- http://service-am-i-ready:80'   # to here
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

应用文件创建pod

k -f 4_pod1.yaml create

检查pod状态

k get pod ready-if-service-ready

file

使用describe检查原因

k describe pod ready-if-service-ready

file

创建第二个pod

k run am-i-ready --image=nginx:1.16.1-alpine --labels="id=cross-server-ready"

检查服务和Endpoint

k describe svc service-am-i-ready
k get ep

file

检查第一个pod运行状态

k get pod ready-if-service-ready

file


Killer.sh CKA模拟题目 汇总