Context -
An existing Pod needs to be integrated into the Kubernetes built-in logging architecture (e.g. kubectl logs). Adding a streaming sidecar container is a good and common way to accomplish this requirement.
Task -
Add a sidecar container named sidecar, using the busybox image, to the existing Pod big-corp-app. The new sidecar container has to run the following command:
ls
Use a Volume, mounted at /var/log, to make the log file big-corp-app.log available to the sidecar container.
Updated Pod YAML Manifest
This assumes you have access to edit the existing Pod big-corp-app. Save the updated configuration to a file (e.g., big-corp-app.yaml) and apply it:
apiVersion: v1
kind: Pod
metadata:
name: big-corp-app
spec:
containers:
- name: main-container
image: your-app-image
volumeMounts:
- name: log-volume
mountPath: /var/log
command: ["/bin/sh", "-c"]
args: ["echo 'Hello from main container!' >> /var/log/big-corp-app.log; sleep 3600"]
- name: sidecar
image: busybox
volumeMounts:
- name: log-volume
mountPath: /var/log
command: ["/bin/sh", "-c"]
args: ["tail -f /var/log/big-corp-app.log"]
volumes:
- name: log-volume
emptyDir: {}
Task -
From the pod label name=overloaded-cpu, find pods running high CPU workloads and write the name of the pod consuming most CPU to the file /opt/
KUTR00401/KUTR00401.txt (which already exists).
root@master:/opt/k8sconfig$sudo kubectl top pods -l name=voerloaded-ccpu --sort-by=cpu
Task -
A Kubernetes worker node, named wk8s-node-0 is in state NotReady.
Investigate why this is the case, and perform any appropriate steps to bring the node to a Ready state, ensuring that any changes are made permanent.
(这个题目其实是因为node上的kubelet停止了导致了node不ready)
Task -
Create a new PersistentVolumeClaim:
✑ Name: pv-volume
✑ Class: csi-hostpath-sc
✑ Capacity: 10Mi
Create a new Pod which mounts the PersistentVolumeClaim as a volume:
✑ Name: web-server
✑ Image: nginx
✑ Mount path: /usr/share/nginx/html
Configure the new Pod to have ReadWriteOnce access on the volume.
Finally, using kubectl edit or kubectl patch expand the PersistentVolumeClaim to a capacity of 70Mi and record that change.
pvc-pv-volume.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv-volume
spec:
storageClassName: csi-hostpath-sc
capacity:
storage: 10Mi
https://kubernetes.io/docs/concepts/storage/persistent-volumes/
pod-web-server.yaml
apiVersion: v1
kind: Pod
metadata:
name: pv-volume-pod
spec:
containers:
- name: web-server
image: nginx
volumeMounts:
- name: pv-test
mountPath: /usr/share/nginx/html
volumes:
- name: pv-test
persistentVolumeClass: csi-hostpath-sc
Cliamname: pv-volume
kubectl edit pvc pv-volume 此命令去edit storage
Task -
Create a new nginx Ingress resource as follows:
✑ Name: pong
✑ Namespace: ing-internal
✑ Exposing service hello on path /hello using service port 5678
考试时候,先定位到kubernets官网上关于ingress部分,然后copy里面的yaml example 改写即可
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: pong
namespace: ing-internal
spec:
ingressClassName: nginx # 定义ingress的类型为nginx,通常nginx是default,可以不显性设定
rules:
- http:
paths:
- path: /hello
pathType: Prefix
backend:
service:
name: hello # backend的service是“hello”
port:
number: 5678
Task -
Schedule a Pod as follows:
• Name: kucc1
• App Containers: 2
• Container Name/images:
o redis
o consul
考试时候,先定位到kubernets官网上关于pod部分,然后copy里面的yaml example 改写即可
apiVersion: v1
kind: Pod
metadata:
name: kucc1
spec:
containers:
- name: redis
image: redis
imagePullPolicy: IfNotPresent
- name: consul
image: consul
imagePullPolicy: IfNotPresent