프로그램/SKT FLY AI
SKT FLY AI : 15일차 - K8s
hsloth
2023. 7. 14. 17:41
minikube start
kubectl get pods
kubectl describe pod <pod-name> # pod-name은 옵셔널이다.
# pod의 로그 출력
kubectl logs <pod-name>
kubectl logs <pod-name> -f # 실시간으로 출력
# Pod 내부 접속
kubectl exec -it <pod-name> -- <command>
# pod안에 컨테이너가 여러개인 경우
kubectl exec -it <pod-name> -c <container-name> -- <command>
# Pod 삭제 - pod를 삭제하면 k8s가 관리하던 이미지도 지워진다.
kubectl delete pod <pod-name>
# 보편적으로는
kubectl delete <구성요소> <요소의 이름>
# -f 옵션은 파일 경로를 나타낸다
kubectl delete -f <yaml파일>
# nginx로 port forwarding
# nginx 포트확인은 도커허브 이미지를 확인하자. 이미지마다 nginx.conf에 설정되어있는 port가 다를 수 있으니까...
kubectl run nginx --image nginx --port=80
kubectl port-forward nginx 18080:80
K8s로 다운받은 이미지는 Docker가 관리하는게 아니라서 docker images
로 보이지 않는다.
하지만, 어딘가에 이미지가 존재한다.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
kubectl apply -f deployment.yaml
kubectl get deployment
kubectl scale deployment/nginx-deployment --replicas=5
kubectl get pod -o wide # pod의 ip확인
curl -X GET <POD-IP> -vvv # 실행안되어야 정상
minikube ssh # minikube master안에 접속
curl -X GET <POD-IP> -vvv # 이제된다.
ping <ip> # 핑도간다.
Service
# svc.yaml
apiVersion: v1
kind: Service
metadata:
name: my-nginx
labels:
run: my-nginx
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
selector:
app: nginx
kubectl apply -f svc.yaml
kubectl ger service # 포트번호 확인 뒤에있는 port 확인
curl -X GET $(minikube ip):<PORT> # port만 바꿔서 입력.