kubectl config use-context k8s-t7Switched to context "k8s-t7".kubectl get pod -l app=frontend --show-labelskubectl patch svc frontend-svc --type=json -p '[ {"op":"replace","path":"/spec/selector","value":{"app":"frontend"}}, {"op":"replace","path":"/spec/ports/0/targetPort","value":80}]'kubectl config use-context k8s-t8Switched to context "k8s-t8".kubectl describe pod crashy | tail -5kubectl logs crashy --tail=5 || truekubectl delete pod crashy probey --nowcat <<'YAML' | kubectl apply -f -apiVersion: v1kind: Podmetadata: {name: crashy}spec: containers: - name: app image: nginx---apiVersion: v1kind: Podmetadata: {name: probey}spec: containers: - name: app image: nginx livenessProbe: httpGet: {path: /, port: 80} initialDelaySeconds: 3 periodSeconds: 3YAMLkubectl config use-context k8s-t9Switched to context "k8s-t9".kubectl describe pod hungry | tail -3kubectl get pod hungry -o yaml | sed -E 's/^( +cpu: )"?50"?$/\1100m/' > /tmp/hungry.yamlkubectl replace --force -f /tmp/hungry.yamlkubectl label node node01 gpu=true --overwrite
kubectl config use-context k8s-t11Switched to context "k8s-t11".kubectl logs noisy | grep ERROR > /opt/noisy-errors.txtkubectl get events -A --sort-by=.metadata.creationTimestamp > /opt/events.txtif kubectl top pod -n kube-system >/dev/null 2>&1; then kubectl top pod -n kube-system --sort-by=memory --no-headers | head -1 | cut -d' ' -f1 > /opt/top-mem.txtfi
kubectl config use-context k8s-t3Switched to context "k8s-t3".crictl ps -a --name kube-apiserver || truesed -i 's#--etcd-servers=https://127.0.0.1:2380#--etcd-servers=https://127.0.0.1:2379#' /etc/kubernetes/manifests/kube-apiserver.yamlsystemctl restart kubelet
kubectl config use-context k8s-c1Switched to context "k8s-c1".grep -E -- '--(listen-client-urls|trusted-ca-file|cert-file|key-file)=' /etc/kubernetes/manifests/etcd.yamlETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \ --cacert=/etc/kubernetes/pki/etcd/ca.crt \ --cert=/etc/kubernetes/pki/etcd/server.crt \ --key=/etc/kubernetes/pki/etcd/server.key \ snapshot save /opt/etcd-backup.dbif command -v etcdutl >/dev/null; then etcdutl snapshot status /opt/etcd-backup.db -w tableelse ETCDCTL_API=3 etcdctl snapshot status /opt/etcd-backup.db -w tablefi
kubectl config use-context k8s-c6Switched to context "k8s-c6".openssl genrsa -out /opt/jane.key 2048openssl req -new -key /opt/jane.key -subj "/CN=jane" -out /opt/jane.csrcat <<EOF | kubectl apply -f -apiVersion: certificates.k8s.io/v1kind: CertificateSigningRequestmetadata: name: janespec: request: $(base64 -w0 < /opt/jane.csr) signerName: kubernetes.io/kube-apiserver-client usages: ["client auth"]EOFkubectl certificate approve janekubectl get csr jane -o jsonpath='{.status.certificate}' | base64 -d > /opt/jane.crtkubectl create clusterrole node-reader --verb=get,list,watch --resource=nodeskubectl create clusterrolebinding jane-node-reader --clusterrole=node-reader --user=janekubectl config use-context k8s-c5Switched to context "k8s-c5".kubectl -n ops create sa deploy-botkubectl -n ops create role deploy-role --verb=get,list,create,update --resource=deploymentskubectl -n ops create rolebinding deploy-role-binding --role=deploy-role --serviceaccount=ops:deploy-botkubectl auth can-i update deployments -n ops --as=system:serviceaccount:ops:deploy-bot || truekubectl auth can-i delete deployments -n ops --as=system:serviceaccount:ops:deploy-bot || true
kubectl config use-context k8s-c7Switched to context "k8s-c7".helm install web /opt/webapp -n web --create-namespace --set replicaCount=3helm upgrade web /opt/webapp -n web --reuse-values --set image.tag=1.27helm rollback web 1 -n webhelm history web -n web > /opt/helm-history.txtcat /opt/helm-history.txt
kubectl config use-context k8s-c8Switched to context "k8s-c8".cat > /opt/kz/overlays/prod/kustomization.yaml <<'YAML'resources:- ../../basenamespace: prodreplicas:- name: api count: 3labels:- pairs: env: prodYAMLkubectl kustomize /opt/kz/overlays/prodkubectl apply -k /opt/kz/overlays/prod
kubectl config use-context k8s-n2Switched to context "k8s-n2".cat <<'EOF' | kubectl apply -f -apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: db-allow namespace: securespec: podSelector: matchLabels: {app: db} policyTypes: [Ingress] ingress: - from: - podSelector: matchLabels: {app: api} ports: - {protocol: TCP, port: 80}EOFkubectl config use-context k8s-n1Switched to context "k8s-n1".kubectl expose deploy shop --name=shop-svc --port=80 --target-port=80 --type=NodePortkubectl patch svc shop-svc --type=json -p '[{"op":"replace","path":"/spec/ports/0/nodePort","value":30080}]'kubectl config use-context k8s-n4Switched to context "k8s-n4".cat <<'YAML' | kubectl apply -f -apiVersion: networking.k8s.io/v1kind: Ingressmetadata: {name: shop, namespace: default}spec: ingressClassName: nginx rules: - host: shop.local http: paths: - path: /cart pathType: Prefix backend: {service: {name: cart, port: {number: 80}}} - path: /pay pathType: Prefix backend: {service: {name: pay, port: {number: 80}}}YAMLkubectl config use-context k8s-n5Switched to context "k8s-n5".cat <<'YAML' | kubectl apply -f -apiVersion: gateway.networking.k8s.io/v1kind: Gatewaymetadata: {name: main-gw, namespace: default}spec: gatewayClassName: nginx listeners: - {name: http, protocol: HTTP, port: 80}---apiVersion: gateway.networking.k8s.io/v1kind: HTTPRoutemetadata: {name: shop-route, namespace: default}spec: parentRefs: - name: main-gw hostnames: ["shop.local"] rules: - matches: - path: {type: PathPrefix, value: /api} backendRefs: - {name: gw-api, port: 80} - backendRefs: - {name: gw-web, port: 80}YAMLkubectl config use-context k8s-w1Switched to context "k8s-w1".kubectl create deployment web --image=nginx:1.27 --replicas=3kubectl rollout status deployment/web --timeout=120skubectl set image deployment/web nginx=nginx:1.28kubectl rollout status deployment/web --timeout=120skubectl set image deployment/web nginx=nginx:9.99kubectl rollout history deployment/webkubectl rollout undo deployment/web --to-revision=2kubectl rollout status deployment/web --timeout=120skubectl rollout history deployment/web > /opt/web-history.txt
kubectl config use-context k8s-w3Switched to context "k8s-w3".cat <<'YAML' | kubectl apply -f -apiVersion: v1kind: Podmetadata: name: logger namespace: defaultspec: volumes: - name: logs emptyDir: {} initContainers: - name: log-tail image: busybox:1.36 restartPolicy: Always command: ["sh", "-c", "touch /var/log/app.log; tail -f /var/log/app.log"] volumeMounts: - {name: logs, mountPath: /var/log} containers: - name: app image: busybox:1.36 command: ["sh", "-c", "while true; do date >> /var/log/app.log; sleep 5; done"] volumeMounts: - {name: logs, mountPath: /var/log}YAMLkubectl -n default wait --for=condition=Ready pod/logger --timeout=90skubectl config use-context k8s-w6Switched to context "k8s-w6".kubectl -n limited create quota team-quota --hard=pods=3,requests.cpu=1cat <<'YAML' | kubectl apply -n limited -f -apiVersion: v1kind: LimitRangemetadata: name: defaultsspec: limits: - type: Container defaultRequest: {cpu: 100m, memory: 64Mi} default: {cpu: 200m, memory: 128Mi}YAMLkubectl -n limited create deployment q --image=nginx --replicas=5sleep 5kubectl -n limited get events --field-selector reason=FailedCreatekubectl -n limited describe quota team-quotakubectl config use-context k8s-s1Switched to context "k8s-s1".cat <<'EOF' | kubectl apply -f -apiVersion: v1kind: PersistentVolumemetadata: {name: pv-log}spec: capacity: {storage: 1Gi} accessModes: [ReadWriteOnce] persistentVolumeReclaimPolicy: Retain storageClassName: manual hostPath: {path: /pv/log}---apiVersion: v1kind: PersistentVolumeClaimmetadata: {name: pvc-log}spec: accessModes: [ReadWriteOnce] storageClassName: manual resources: {requests: {storage: 500Mi}}---apiVersion: v1kind: Podmetadata: {name: log-pod}spec: containers: - name: web image: nginx volumeMounts: - {name: data, mountPath: /usr/share/nginx/html} volumes: - name: data persistentVolumeClaim: {claimName: pvc-log}EOFkubectl config use-context k8s-s3Switched to context "k8s-s3".kubectl -n default delete pvc pvc-datacat <<'YAML' | kubectl apply -f -apiVersion: v1kind: PersistentVolumeClaimmetadata: {name: pvc-data, namespace: default}spec: accessModes: [ReadWriteOnce] storageClassName: manual volumeName: pv-data resources: {requests: {storage: 1Gi}}YAMLExam complete.19 questions checked, in order.