[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl apply -f sample/pod.yaml
pod/nginx created
Pod 목록 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 10s
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx 1/1 Running 0 2m9s 10.161.35.143 xxxxxxxxxxxxx <none><none>
Pod 상태 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl describe pod nginx
Name: nginx
Namespace: cyj
Priority: 0
Node: xxxxxxxxxxxxx/xxxxxxxxxxxxx
Start Time: Wed, 15 Mar 2023 15:27:20 +0900
Labels: <none>
Status: Running
IP: xxxxxxxxxxxxx
IPs:
IP: xxxxxxxxxxxxx
Containers:
nginx:
Container ID: docker://3cfac59b7c44c25dba8df7b16230dadbba7a8b68ccc1dd173dd68c740e1a169c
Image: nginx:1.14.2
Image ID: docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 15 Mar 2023 15:27:28 +0900
Ready: True
Restart Count: 0
Limits:
cpu: 4
ephemeral-storage: 8Gi
memory: 4Gi
Requests:
cpu: 100m
ephemeral-storage: 8Gi
memory: 512Mi
Environment:
TZ: Asia/Seoul
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-v7p9r (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-v7p9r:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-v7p9r
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 47s default-scheduler Successfully assigned cyj/nginx to xxxxxxxxxxxxx
Normal Pulling 46s kubelet, xxxxxxxxxxxxx Pulling image "nginx:1.14.2"
Normal Pulled 40s kubelet, xxxxxxxxxxxxx Successfully pulled image "nginx:1.14.2"
Normal Created 39s kubelet, xxxxxxxxxxxxx Created container nginx
Normal Started 39s kubelet, xxxxxxxxxxxxx Started container nginx
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ curl 10.161.35.143:80
<!DOCTYPE html><html><head><title>Welcome to nginx!</title><style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p><p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl exec -it nginx -c nginx /bin/bash
root@nginx:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@nginx:/# exit
Pod 삭제하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl delete pod nginx
pod "nginx" deleted
Tutorial 2 - Deployment로 애플리케이션 배포하기
Deployment로 nginx 배포하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl apply -f sample/deployment.yaml
deployment.apps/nginx-deployment created
Pod 목록 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-b974549f7-28nkd 1/1 Running 0 13s
nginx-deployment-b974549f7-8kjh7 1/1 Running 0 13s
Deployment 목록 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 108s
ReplicaSet 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-b974549f7 2 2 2 2m7s
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl apply -f sample/deployment.yaml
deployment.apps/nginx-deployment created
Tutorial 3 - Service로 애플리케이션 외부에 노출하기
Service 생성하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl apply -f sample/service.yaml
service/nginx-svc created
Service 목록 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-svc LoadBalancer 172.24.250.48 10.161.122.175 80:35617/TCP,443:40987/TCP 33s
Service EXTERNAL-IP로 외부에서 접근하기
Tutorial 4 - HPA 사용하기 Part 1
Pod 목록 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-b974549f7-86nzt 1/1 Running 0 5m23s
nginx-deployment-b974549f7-dxj6z 1/1 Running 0 5m23s
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
nginx-deployment Deployment/nginx-deployment <unknown>/3% 2 5 2 22s
deployment 확인하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get deployment
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 7m21s
Pod 목록 조회하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-b974549f7-4bxgz 1/1 Running 0 85s
nginx-deployment-b974549f7-86nzt 1/1 Running 0 8m29s
Pod 리소스 사용량 확인하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl top pod
NAME CPU(cores) MEMORY(bytes)
nginx-deployment-b974549f7-2xh5j 0m 3Mi
nginx-deployment-b974549f7-j826d 0m 3Mi
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl top pod
NAME CPU(cores) MEMORY(bytes)
nginx-deployment-b974549f7-cqt8t 6m 5Mi
nginx-deployment-b974549f7-hrfkp 6m 5Mi
hpa 확인하기
[ec2-user@ip-xxx-xxx-xxx-xxx ~]$ kubectl get hpa
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
nginx-deployment Deployment/nginx-deployment 6%/3% 2 5 4 63s