테스트 소스코드 : https://github.com/kimkevin90/kubernetes_express
이미지 생성
docker build . -t 이미지명
docker build . -t limkevin1313/kubernetes_hello
도커 허브에 배포
docker push 이미지명
docker push limkevin1313/kubernes_hello
Deployment 생성
k create deployment Deployment명 --image=이미지명
k create deployment kube-express --image=limkevin1313/kubernetes_express
Service 생성
k expose deployment Deployment명 --port=서버포트
스케일링
k scale deployment Deployment명 --replicas=4
NordPort
k expose deployment Deployment명 --type=NodePort --port=서버포트
minikube service kube-k8s --url
LoadBalancer
k expose deployment Deployment명 --type=LoadBalancer --port=서버포트
도커 이미지 업데이트
docker build . -t limkevin1313/kubernetes_hello:2.0.0
docker push limkevin1313/kubernetes_hello:2.0.0
kubectl set image deployment-name container-name=image-name
k rollout status deploy k8s // 새로운 레플리카 roll out
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubernetes-hello-seobi
spec:
replicas: 3
selector:
matchLabels:
app: kubernetes-hello-seobi
template:
metadata:
labels:
app: kubernetes-hello-seobi
spec:
containers:
- name: kubernetes-hello-seobi
image: limkevin1313/kubernetes_hello_seobi
resources:
limits:
memory: "128Mi"
cpu: "250m"
ports:
- containerPort: 3000
kubectl apply -f deployment.yaml
service.yaml
apiVersion: v1
kind: Service
metadata:
name: kubernetes-hello-seobi
spec:
type: LoadBalancer
selector:
app: kubernetes-hello-seobi
ports:
- port: 3030
targetPort: 3000
kubectl apply -f service.yaml
kubectl delete -f deployment.yaml -f service.yaml // 삭제
참고 - Kubernetes Course / Bogdan Stashchuk