Use context: kubectl config use-context k8s-c3-CCC

Create a Static Pod named my-static-pod in Namespace default on cluster3-controlplane1 . It should be of image nginx:1.16-alpine and have resource requests for 10m CPU and 20Mi memory.

Then create a NodePort Service named static-pod-service which exposes that static Pod on port 80 and check if it has Endpoints and if it's reachable through the cluster3-controlplane1 internal IP address. You can connect to the internal node IPs from your main terminal.


译文:

cluster3-controlplane1 上创建一个名为 my-static-pod 的命名空间。镜像为 nginx:1.16-alpine ,并且有10m CPU和20Mi内存的资源请求。

然后创建一个名为 static-pod-service 的 NodePort 服务,在80端口公开静态Pod,并检查它是否有Endpoints,是否可以通过 cluster3-controlplane1 的内部IP地址到达。你可以从你的主终端连接到内部节点的IP。


解答:
kubectl config use-context k8s-c3-CCC

连接到cluster3-controlplane1 并新建一个pod

ssh cluster3-controlplane1

root@cluster1-controlplane1:~# cd /etc/kubernetes/manifests/

root@cluster1-controlplane1:~# kubectl run my-static-pod \
    --image=nginx:1.16-alpine \
    -o yaml --dry-run=client > my-static-pod.yaml

my-static-pod.yaml

# /etc/kubernetes/manifests/my-static-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: my-static-pod
  name: my-static-pod
spec:
  containers:
  - image: nginx:1.16-alpine
    name: my-static-pod
    resources:                     #change
      requests:                    #add
        cpu: 10m                   #add
        memory: 20Mi               #add
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

返回操作节点,检查pod

k get pod -A | grep my-static

file

暴露端口

k expose pod my-static-pod-cluster3-controlplane1 \
  --name static-pod-service \
  --type=NodePort \
  --port 80

检查

k get svc,ep -l run=my-static-pod

file


Killer.sh CKA模拟题目 汇总