apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: app
name: ingress-myapp
annotations:
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
spec:
ingressClassName: alb
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-1234
port:
number: 80
apiVersion: apps/v1
kind: Deployment
...
spec:
template:
metadata:
name: myapp-deploy
spec:
containers:
- name: nginx
image: nginx
resources:
requests:
cpu: 1
memory: "1Gi"
limits:
cpu: 3
memory: "2Gi"
replicas: 3
selector:
matchLabels:
type: front-end
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: sample-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp-deploy
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
apiVersion: apps/v1
kind: Deployment
...
spec:
template:
metadata:
name: myapp-deploy
spec:
containers:
- name: nginx
image: nginx
resources:
requests:
cpu: 180m
memory: 50Mi
limits:
cpu: 600m
memory: 100Mi
replicas: 3
selector:
matchLabels:
type: front-end
apiVersion:
autoscaling.k8s.io/v1beta2
kind: VerticalPodAutoscaler
metadata:
name: nginx-vpa
namespace: vpa
spec:
TargetRef:
apiVersion: "apps/v1"
kind: Deployment
name: nginx
updatePolicy:
updateMode: "Auto"
resourcePolicy:
containerPolicies:
- containerName: "nginx"
minAllowed:
cpu: "250m"
memory: "100Mi"
maxAllowed:
cpu: "500m"
memory: "600Mi"
apiVersion: v1
kind: Pod
metadata:
name: nginx-env
spec:
containers:
- name: nginx-env
image: nginx
ports:
- containerPort:8080
env:
- name: APP_COLOR
value: pink
# env가 설정된 pod 생성
$ k apply -f env-pod.yaml
# env 확인
$ k exec nginx-env -it -- /bin/sh
$ (pod shell) env
apiVersion: v1
kind: Configmap
metadata:
name: test-config
data:
APP_COLOR: blue
APP_MODE: prod
configmap 전체를 injection
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: nginx
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: test-config
configmap 일부를 injection
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: nginx
ports:
- containerPort: 8080
env:
- name: APP_COLOR
valueFrom:
configMapKeyRef:
name: test-config
key: APP_COLOR
# 직접 값을 전달하여 생성
$ k create configmap --save-config test2-config --from-literal=app=pink --from-literal=connection.max=100
$ k get cm test2-config -o yaml | yq .data
# 파일에서 값을 참고하여 생성
$ k create configmap --save-config test3-config --from-file=nginx.conf
$ k get cm test3-config -o yaml | yq .data
apiVersion: v1
kind: Configmap
metadata:
name: test3-config
data:
nginx.conf: ...
configmap 전체를 injection
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: nginx
volumeMounts:
- name: config-volume
mountPath: /config
volumes:
- name: config-volume
configMap:
name: test3-config
configmap 일부를 injection
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: nginx
volumeMounts:
- name: config-volume
mountPath: /config
volumes:
- name: config-volume
configMap:
name: test3-config
items:
- key: nginx.conf
path: nginx-sample.conf
apiVersion: v1
kind : Secret
metadata: test-secret
data:
DB_Host: xxxxx
DB_User: xxxxxx
DB_Password: xxxxxx
secret 전체를 injection
apiVersion: v1
kind : Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: nginx
ports:
- containerPort: 8080
envFrom:
- secretKeyRef:
name: test-secret
secret 일부를 injection
apiVersion: v1
kind : Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: nginx
ports:
- containerPort: 8080
env:
- name: DB_Password
valueFrom:
secretKeyRef:
name: test-secret
key: DB_Password
# 직접 값을 전달하여 생성
$ k create secret generic --save-config test2-secret --from-literal password=test123
$ k get secret test2-secret -o yaml | yq .data
$ echo -n '<인코드값>' | base64 -d
# env 파일 값을 전달하여 생성
$ k create secret generic --save-config test3-secret --from-env-file db-secret.txt
$ k get secret test3-secret -o yaml | yq .data
$ echo -n '<인코드값>' | base64 -d
emptyDir
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
container:
- image:
registry.k8s.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /cache
name: cache-volume
volumes:
- name: cache-volume
emptyDir:
sizeLimit: 500Mi
hostPath
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
container:
- image:
registry.k8s.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
volumes:
- name: test-volume
hostPath:
# directory location on host path: /data
# this field is optional type: Directory
# AWS EBS
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: slow
provisioner: kubernetes.io/aws-ebs
parameters:
type: io1
iopsPerGB: "10"
fsType: ext4