231 lines
4.7 KiB
Markdown
231 lines
4.7 KiB
Markdown
# Task 1
|
|
|
|
```bash
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
labels:
|
|
run: mc-pod
|
|
name: mc-pod
|
|
namespace: mc-namespace
|
|
spec:
|
|
containers:
|
|
- image: nginx:1-alpine
|
|
name: mc-pod-1
|
|
env:
|
|
- name: NODE_NAME
|
|
valueFrom:
|
|
fieldRef:
|
|
fieldPath: spec.nodeName
|
|
- image: busybox:1
|
|
name: mc-pod-2
|
|
command: ["sh", "-c"]
|
|
args: ["while true; do date >> /var/log/shared/date.log; sleep 1; done"]
|
|
volumeMounts:
|
|
- mountPath: /var/log/shared
|
|
name: shared-log
|
|
- image: busybox:1
|
|
name: mc-pod-3
|
|
command: ["sh", "-c"]
|
|
args: ["tail -f /var/log/shared/date.log"]
|
|
volumeMounts:
|
|
- mountPath: /var/log/shared
|
|
name: shared-log
|
|
volumes:
|
|
- name: shared-log
|
|
emptyDir:
|
|
sizeLimit: 500Mi
|
|
|
|
|
|
echo "verticalpodautoscalercheckpoints" >> /root/vpa-crds.txt
|
|
echo "verticalpodautoscalers" >> /root/vpa-crds.txt
|
|
|
|
|
|
kubectl expose pod messaging --port=6379 --name=messaging-service
|
|
|
|
kubectl create deployment hr-web-app --image=kodekloud/webapp-color --replicas=2
|
|
|
|
cat webapp-hpa.yaml
|
|
apiVersion: autoscaling/v2
|
|
kind: HorizontalPodAutoscaler
|
|
metadata:
|
|
name: webapp-hpa
|
|
namespace: default
|
|
spec:
|
|
scaleTargetRef:
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
name: kkapp-deploy
|
|
minReplicas: 2
|
|
maxReplicas: 10
|
|
|
|
|
|
|
|
cat pv.yaml
|
|
apiVersion: v1
|
|
kind: PersistentVolume
|
|
metadata:
|
|
name: pv-analytics
|
|
spec:
|
|
hostPath:
|
|
path: /pv/data-analytics
|
|
accessModes:
|
|
- ReadWriteMany
|
|
capacity:
|
|
storage: 100Mi
|
|
|
|
cat orange.yaml
|
|
apiVersion: v1
|
|
kind: Pod
|
|
metadata:
|
|
creationTimestamp: "2026-07-21T19:20:48Z"
|
|
generation: 1
|
|
name: orange
|
|
namespace: default
|
|
resourceVersion: "4629"
|
|
uid: 3a8c1925-7db8-4518-9489-e6ae2e814ac5
|
|
spec:
|
|
containers:
|
|
- command:
|
|
- sh
|
|
- -c
|
|
- echo The app is running! && sleep 3600
|
|
image: busybox:1.28
|
|
imagePullPolicy: IfNotPresent
|
|
name: orange-container
|
|
resources: {}
|
|
terminationMessagePath: /dev/termination-log
|
|
terminationMessagePolicy: File
|
|
volumeMounts:
|
|
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
|
|
name: kube-api-access-jhc2d
|
|
readOnly: true
|
|
dnsPolicy: ClusterFirst
|
|
enableServiceLinks: true
|
|
initContainers:
|
|
- command:
|
|
- sh
|
|
- -c
|
|
- sleep 2;
|
|
image: busybox
|
|
imagePullPolicy: Always
|
|
name: init-myservice
|
|
resources: {}
|
|
terminationMessagePath: /dev/termination-log
|
|
terminationMessagePolicy: File
|
|
volumeMounts:
|
|
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
|
|
name: kube-api-access-jhc2d
|
|
readOnly: true
|
|
nodeName: controlplane
|
|
preemptionPolicy: PreemptLowerPriority
|
|
priority: 0
|
|
restartPolicy: Always
|
|
schedulerName: default-scheduler
|
|
securityContext: {}
|
|
serviceAccount: default
|
|
serviceAccountName: default
|
|
terminationGracePeriodSeconds: 30
|
|
tolerations:
|
|
- effect: NoExecute
|
|
key: node.kubernetes.io/not-ready
|
|
operator: Exists
|
|
tolerationSeconds: 300
|
|
- effect: NoExecute
|
|
key: node.kubernetes.io/unreachable
|
|
operator: Exists
|
|
tolerationSeconds: 300
|
|
volumes:
|
|
- name: kube-api-access-jhc2d
|
|
projected:
|
|
defaultMode: 420
|
|
sources:
|
|
- serviceAccountToken:
|
|
expirationSeconds: 3607
|
|
path: token
|
|
- configMap:
|
|
items:
|
|
- key: ca.crt
|
|
path: ca.crt
|
|
name: kube-root-ca.crt
|
|
- downwardAPI:
|
|
items:
|
|
- fieldRef:
|
|
apiVersion: v1
|
|
fieldPath: metadata.namespace
|
|
path: namespace
|
|
|
|
kubectl expose deployment hr-web-app --port=8080 --type=NodePort --name=hr-web-app-service
|
|
|
|
-----------
|
|
|
|
cat /root/webapp-hpa.yaml
|
|
apiVersion: autoscaling/v2
|
|
kind: HorizontalPodAutoscaler
|
|
metadata:
|
|
name: webapp-hpa
|
|
spec:
|
|
maxReplicas: 10
|
|
metrics:
|
|
- resource:
|
|
name: cpu
|
|
target:
|
|
averageUtilization: 50
|
|
type: Utilization
|
|
type: Resource
|
|
minReplicas: 1
|
|
scaleTargetRef:
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
name: kkapp-deploy
|
|
status:
|
|
currentMetrics: null
|
|
desiredReplicas: 0
|
|
|
|
----------------------------
|
|
|
|
# vpa
|
|
# ----------------
|
|
|
|
apiVersion: autoscaling.k8s.io/v1
|
|
kind: VerticalPodAutoscaler
|
|
metadata:
|
|
name: analytics-vpa
|
|
namespace: default
|
|
spec:
|
|
targetRef:
|
|
apiVersion: apps/v1
|
|
kind: Deployment
|
|
name: analytics-deployment
|
|
updatePolicy:
|
|
updateMode: "Recreate"
|
|
resourcePolicy:
|
|
containerPolicies:
|
|
- containerName: "*"
|
|
controlledResources: ["cpu", "memory"]
|
|
|
|
# -----------------
|
|
# gateway
|
|
# -------
|
|
|
|
apiVersion: gateway.networking.k8s.io/v1
|
|
kind: Gateway
|
|
metadata:
|
|
name: web-gateway
|
|
namespace: nginx-gateway
|
|
spec:
|
|
gatewayClassName: nginx
|
|
listeners:
|
|
- name: http
|
|
protocol: HTTP
|
|
port: 80
|
|
allowedRoutes:
|
|
namespaces:
|
|
from: Same
|
|
|
|
# --------
|
|
helm upgrade -n kk-ns kk-mock1 kk-mock1/podinfo --version 6.11.2
|
|
|
|
# --------
|
|
|
|
``` |