docs: add Kubernetes CKS study notes
This commit is contained in:
237
kubernetes/mock exams/exam-3.md
Normal file
237
kubernetes/mock exams/exam-3.md
Normal file
@@ -0,0 +1,237 @@
|
||||
# Task 1
|
||||
|
||||
```bash
|
||||
sysctl net.ipv4.ip_forward=1
|
||||
sysctl net.bridge.bridge-nf-call-iptables=1
|
||||
|
||||
# it is already persistent: /etc/sysctl.d/k8s.conf
|
||||
```
|
||||
|
||||
# Task 2
|
||||
|
||||
```bash
|
||||
kubectl create serviceaccount pvviewer
|
||||
kubectl create clusterrole pvviewer-role --verb=list --resource=persistentVolumes
|
||||
kubectl create clusterrolebinding pvviewer-role-binding --clusterrole=pvviewer-role --serviceaccount=default:pvviewer
|
||||
k run pvviewer --image=redis -o yaml --dry-run > p.yaml
|
||||
|
||||
# edit -> add serviceAccount -> apply
|
||||
|
||||
```
|
||||
|
||||
# Task 3
|
||||
|
||||
```bash
|
||||
cat sc.yaml
|
||||
apiVersion: storage.k8s.io/v1
|
||||
kind: StorageClass
|
||||
metadata:
|
||||
name: rancher-sc
|
||||
provisioner: rancher.io/local-path
|
||||
volumeBindingMode: WaitForFirstConsumer
|
||||
```
|
||||
|
||||
# Task 4
|
||||
|
||||
```bash
|
||||
kubectl create configmap app-config -n cm-namespace --from-litera
|
||||
l=ENV=production --from-literal=LOG_LEVEL=info
|
||||
|
||||
k get deployments.apps -n cm-namespace cm-webapp -o yaml | yq .spec
|
||||
progressDeadlineSeconds: 600
|
||||
replicas: 1
|
||||
revisionHistoryLimit: 10
|
||||
selector:
|
||||
matchLabels:
|
||||
app: cm-webapp
|
||||
strategy:
|
||||
rollingUpdate:
|
||||
maxSurge: 25%
|
||||
maxUnavailable: 25%
|
||||
type: RollingUpdate
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: cm-webapp
|
||||
spec:
|
||||
containers:
|
||||
- env:
|
||||
- name: LOG_LEVEL
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
key: LOG_LEVEL
|
||||
name: app-config
|
||||
- name: ENV
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
key: ENV
|
||||
name: app-config
|
||||
image: nginx
|
||||
imagePullPolicy: Always
|
||||
name: nginx
|
||||
resources: {}
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
securityContext: {}
|
||||
terminationGracePeriodSeconds: 30
|
||||
```
|
||||
|
||||
# Task 5
|
||||
|
||||
```bash
|
||||
cat pc.yaml
|
||||
apiVersion: scheduling.k8s.io/v1
|
||||
kind: PriorityClass
|
||||
metadata:
|
||||
name: low-priority
|
||||
value: 50000
|
||||
```
|
||||
|
||||
# Task 6
|
||||
|
||||
```bash
|
||||
cat np.yaml
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: ingress-to-nptest
|
||||
spec:
|
||||
podSelector:
|
||||
matchLabels:
|
||||
run: np-test-1
|
||||
ingress:
|
||||
- ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
policyTypes:
|
||||
- Ingress
|
||||
```
|
||||
|
||||
# Task 7
|
||||
|
||||
```bash
|
||||
k taint node node01 kodekloud:NoSchedule
|
||||
k run dev-redis --image redis:alpine
|
||||
k run prod-redis --image redis:alpine -o yaml --dry-run > p7.yaml
|
||||
|
||||
cat p7.yaml
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
labels:
|
||||
run: prod-redis
|
||||
name: prod-redis
|
||||
spec:
|
||||
containers:
|
||||
- image: redis:alpine
|
||||
name: prod-redis
|
||||
resources: {}
|
||||
dnsPolicy: ClusterFirst
|
||||
restartPolicy: Always
|
||||
tolerations:
|
||||
- key: "kodekloud"
|
||||
operator: "Exists"
|
||||
effect: "NoSchedule"
|
||||
```
|
||||
|
||||
# Task 8
|
||||
|
||||
```bash
|
||||
# k get storageClasses
|
||||
# fix accessMode
|
||||
kubectl get pvc app-pvc -n storage-ns -o yaml > pvc.yaml
|
||||
|
||||
cat pvc.yaml | yq .spec
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
volumeMode: Filesystem
|
||||
|
||||
```
|
||||
|
||||
# Task 9
|
||||
|
||||
```bash
|
||||
# fix port to api server in kubeconfig
|
||||
|
||||
```
|
||||
|
||||
# Task 10
|
||||
|
||||
```bash
|
||||
k scale deployment nginx-deploy --replicas=3
|
||||
|
||||
# /etc/kubernetes/manifests/controller-manager ... typo in command
|
||||
```
|
||||
|
||||
# Task 11
|
||||
|
||||
```bash
|
||||
# hpa
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: api-hpa
|
||||
namespace: api
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: api-deployment
|
||||
minReplicas: 1
|
||||
maxReplicas: 20
|
||||
metrics:
|
||||
- type: Pods
|
||||
pods:
|
||||
metric:
|
||||
name: requests_per_second
|
||||
target:
|
||||
type: AverageValue
|
||||
averageValue: "1000"
|
||||
```
|
||||
|
||||
# Task 12
|
||||
|
||||
```bash
|
||||
# httproute
|
||||
cat httproute.yaml
|
||||
apiVersion: gateway.networking.k8s.io/v1
|
||||
kind: HTTPRoute
|
||||
metadata:
|
||||
name: web-route
|
||||
spec:
|
||||
parentRefs:
|
||||
- name: web-gateway
|
||||
rules:
|
||||
- matches:
|
||||
- path:
|
||||
type: PathPrefix
|
||||
value: /
|
||||
backendRefs:
|
||||
- name: web-service
|
||||
port: 80
|
||||
weight: 80
|
||||
- name: web-service-v2
|
||||
port: 80
|
||||
weight: 20
|
||||
```
|
||||
|
||||
# Task 13
|
||||
|
||||
```bash
|
||||
helm install webpage-server-02 /root/new-version/
|
||||
helm uninstall webpage-server-01
|
||||
```
|
||||
|
||||
# Task 14
|
||||
|
||||
```bash
|
||||
k get cm -n kube-system kubeadm-config -o yaml
|
||||
echo "172.17.0.0/16" > /root/pod-cidr.txt
|
||||
```
|
||||
Reference in New Issue
Block a user