Q3
以下の条件でPodを起動する
namespace:ckad ※ない場合作成する
Pod名:resourcepod
使用するイメージ:nginx
CPUリソース要求:50m
CPUリソースリミット:100m
メモリーリソース要求:50Mi
メモリーリソースリミット:100Mi
A3
kubetl get ns/kubectl run/kubectl applyの使用
kubeuser@master01:~$ kubectl get ns NAME STATUS AGE blue Active 281d cadvisor Active 237d default Active 297d ingress-nginx Active 295d istio-system Active 72d kube-node-lease Active 297d kube-public Active 297d kube-system Active 297d kubernetes-dashboard Active 284d metallb-system Active 296d orange Active 281d kubeuser@master01:~$ kubectl create ns ckad namespace/ckad created kubeuser@master01:~$ kubectl get ns NAME STATUS AGE blue Active 281d cadvisor Active 237d ckad Active 3s default Active 297d ingress-nginx Active 295d istio-system Active 72d kube-node-lease Active 297d kube-public Active 297d kube-system Active 297d kubernetes-dashboard Active 284d metallb-system Active 296d orange Active 281d
kubeuser@master01:~$ kubectl run resourcepod --image=nginx -n ckad --dry-run=client -o yaml > q3_pod.yaml kubeuser@master01:~$ cat q3_pod.yaml apiVersion: v1 kind: Pod metadata: creationTimestamp: null labels: run: resourcepod name: resourcepod namespace: ckad spec: containers: - image: nginx name: resourcepod resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {} kubeuser@master01:~$ vi q3_pod.yaml kubeuser@master01:~$ cat q3_pod.yaml apiVersion: v1 kind: Pod metadata: labels: run: resourcepod name: resourcepod namespace: ckad spec: containers: - image: nginx name: resourcepod resources: requests: memory: "50Mi" cpu: "50m" limits: memory: "100Mi" cpu: "100m"
kubeuser@master01:~$ kubectl apply -f q3_pod.yaml pod/resourcepod created kubeuser@master01:~$ kubectl get pod -n ckad NAME READY STATUS RESTARTS AGE resourcepod 1/1 Running 0 18s
kubeuser@master01:~$ kubectl describe pod resourcepod -n ckad Name: resourcepod Namespace: ckad Priority: 0 Service Account: default Node: worker02/192.168.1.46 Start Time: Sat, 06 Jan 2024 07:53:16 +0000 Labels: run=resourcepod Annotations: cni.projectcalico.org/containerID: 5a30eb9898efc22c653f6b8fc443d09d4b4e351198fc72826dbb2ce243a02aa4 cni.projectcalico.org/podIP: 10.0.30.67/32 cni.projectcalico.org/podIPs: 10.0.30.67/32,fd12:b5e0:383e:0:7bf:50a7:b256:1e5c/128 Status: Running IP: 10.0.30.67 IPs: IP: 10.0.30.67 IP: fd12:b5e0:383e:0:7bf:50a7:b256:1e5c Containers: resourcepod: Container ID: containerd://0195e66d4b4fa81009f10aa9b7f2f9f043dbca360130d79fd9958d2a90e52abf Image: nginx Image ID: docker.io/library/nginx@sha256:2bdc49f2f8ae8d8dc50ed00f2ee56d00385c6f8bc8a8b320d0a294d9e3b49026 Port: <none> Host Port: <none> State: Running Started: Sat, 06 Jan 2024 07:53:24 +0000 Ready: True Restart Count: 0 Limits: cpu: 100m memory: 100Mi Requests: cpu: 50m memory: 50Mi Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-t99h6 (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: kube-api-access-t99h6: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: <nil> DownwardAPI: true QoS Class: Burstable Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 2m5s default-scheduler Successfully assigned ckad/resourcepod to worker02 Normal Pulling 2m2s kubelet Pulling image "nginx" Normal Pulled 118s kubelet Successfully pulled image "nginx" in 3.916486474s (3.916663084s including waiting) Normal Created 117s kubelet Created container resourcepod Normal Started 117s kubelet Started container resourcepod
おまけ:削除
kubeuser@master01:~$ kubectl delete pod resourcepod -n ckad --force Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely. pod "resourcepod" force deleted kubeuser@master01:~$ kubectl delete ns ckad namespace "ckad" deleted
参照本家サイト
Resource Management for Pods and Containers
https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/