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 的名称空间 default 中创建一个名为 my-static-pod 的静态 Pod。 镜像为 nginx:1.16-alpine ,并有 10m CPU 和 20Mi 内存的资源请求

然后创建一个名为 static-pod-service 的 NodePort 服务,通过 80 端口公开该静态 Pod,并检查它是否有端点,以及是否可以通过 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

create-pod-svc-0

暴露端口

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

create-pod-svc-1