apiVersion: v1
kind: Pod
metadata:
name: pod1
labels:
type: web
spec:
containers:
- name: container
image: 이미지이름
ports:
- containerPort: 8000
terminationGracePeriodSeconds: 0 # 삭제시간 0초
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: replica1
spec:
replicas: 1
selector:
matchLabels:
type: web
template:
metadata:
name: pod1
labels:
type: web
spec:
containers:
- name: container
image: gugucone/hello:8000
ports:
- containerPort: 8000
terminationGracePeriodSeconds: 0
matchExpressions:
- {key: type, operator: In, values: [web]}
# 키: type이고 연산자의 값이 web이면 매치!
- {key: ver, operator: Exists}
# 키: ver이면 연사자가 존재하면 매치!
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-1
spec:
replicas: 2
strategy:
type: Recreate
revisionHistoryLimit: 1
# 업데이트내역 기록해주는 것! 이거는 명령어로 확인해보자
selector:
matchLabels:
type: app
template:
metadata:
labels:
type: app
spec:
containers:
- name: container
image: gugucone/hello:8000
ports:
- containerPort: 8000
terminationGracePeriodSeconds: 5
현재 업데이트 내역 확인
kubectl rollout history deployment [디플로이먼트이름]
이전 버전으로 돌아가기
kubectl rollout undo deployment [디플로이먼트이름] --to-revision=[위에서 확인한 숫자]
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-2
spec:
selector:
matchLabels:
type: app
replicas: 4
strategy:
type: RollingUpdate
minReadySeconds: 10
# 10초동안 건들지말아줘! 트래픽이 오지 않도록
template:
metadata:
labels:
type: app
spec:
containers:
- name: container
image: gugucone/hello:8000
terminationGracePeriodSeconds: 3
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-test-1
spec:
selector:
matchLabels:
ver: v1
replicas: 2
strategy:
type: RollingUpdate
minReadySeconds: 10
template:
metadata:
labels:
ver: v1
spec:
containers:
- name: container
image: gugucone/hello:v1.1
terminationGracePeriodSeconds: 3
apiVersion: apps/v1
kind: Deployment
metadata:
name: deployment-test-2
spec:
selector:
matchLabels:
ver: v2
replicas: 2
strategy:
type: RollingUpdate
minReadySeconds: 10
template:
metadata:
labels:
ver: v2
spec:
containers:
- name: container
image: gugucone/hello:v2.1
terminationGracePeriodSeconds: 3
apiVersion: v1
kind: Service
metadata:
name: test-svc
spec:
selector:
ver: v1 #이친구만 변경해주면 된다!
ports:
- port: 80
targetPort: 80
type: LoadBalancer
while true; do curl http://192.168.181.102/; sleep 1; done
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.6.3/components.yaml
args:
- '--cert-dir=/tmp'
- '--secure-port=443'
- '--kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname'
- '--kubelet-use-node-status-port'
- '--metric-resolution=15s'
- '--kubelet-insecure-tls' # 이 친구를 추가
apiVersion: apps/v1
kind: Deployment
metadata:
name: cpu1
spec:
selector:
matchLabels:
resource: cpu
replicas: 2
template:
metadata:
labels:
resource: cpu
spec:
containers:
- name: container
image: gugucone/hello:v1.1
resources:
requests:
cpu: 100m
limits:
cpu: 200m
apiVersion: v1
kind: Service
metadata:
name: auto-svc
spec:
selector:
resource: cpu
ports:
- port: 80
targetPort: 80
type: LoadBalancer
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: hpa-resource-cpu
spec:
maxReplicas: 10
minReplicas: 2
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: cpu1
# 누구를 target으로 할 것이냐!
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 15
# 사용량 설정
kubectl get hpa -w
실시간으로 사용량을 확인할 수 있다.