kubernetes/udemy

[Udemy] Pod 생성 및 삭제

bbiyak2da 2025. 2. 12. 14:26

Pod 생성

 

# AKS 생성

 

Portal에서 AKS 클러스터 생성

 

AKS를 생성하게 되면, 이에 필요한 인프라 리소스들도 자동으로 생성된다.

차근차근히 알아가보자!

 

# AKS 클러스터에 대한 Kubernetes 구성 파일(kubeconfig)을 설정

# az login
az login

# Configure Cluster Creds (kube config) for Azure AKS Clusters
az aks get-credentials --resource-group aks-rg1 --name aksdemo1

# Get Worker Node Status
kubectl get nodes
---
NAME                                STATUS   ROLES    AGE   VERSION
aks-agentpool-29221675-vmss000000   Ready    <none>   18m   v1.30.7
aks-agentpool-29221675-vmss000001   Ready    <none>   18m   v1.30.7

# Get Worker Node Status with wide option
kubectl get nodes -o wide

 

# Pod 생성

# Template
kubectl run <desired-pod-name> --image <Container-Image> 

# Replace Pod Name, Container Image
kubectl run my-first-pod --image stacksimplify/kubenginx:1.0.0

 

# Pod 확인

# List Pods
kubectl get pods

# Alias name for pods is po
kubectl get po

# List Pods with wide option
kubectl get pods -o wide
---
NAME           READY   STATUS    RESTARTS   AGE    IP            NODE                                NOMINATED NODE   READINESS GATES
my-first-pod   1/1     Running   0          102s   10.224.0.95   aks-agentpool-29221675-vmss000000   <none>           <none>

 

# describe 명령어로 더 구체적으로 pod 확인

kubectl describe pod my-first-pod
---
Name:             my-first-pod
Namespace:        default
Priority:         0
Service Account:  default
Node:             aks-agentpool-29221675-vmss000000/10.224.0.4
Start Time:       Wed, 12 Feb 2025 14:11:29 +0900
Labels:           run=my-first-pod
Annotations:      <none>
Status:           Running
IP:               10.224.0.95
IPs:
  IP:  10.224.0.95
...
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  3m36s  default-scheduler  Successfully assigned default/my-first-pod to aks-agentpool-29221675-vmss000000  
  Normal  Pulling    3m35s  kubelet            Pulling image "stacksimplify/kubenginx:1.0.0"
  Normal  Pulled     3m28s  kubelet            Successfully pulled image "stacksimplify/kubenginx:1.0.0" in 7.208s (7.208s including waiting). Image size: 51029957 bytes.
  Normal  Created    3m28s  kubelet            Created container my-first-pod

 

외부에서 Pod 내 애플리케이션에 접근하기 위해서, Nodeport 또는 Load Balancer가 필요한데

다음 시간에 적용해보기로 하고 Pod를 삭제해보자

 

# Pod 삭제

# To get list of pod names
kubectl get pods

# Delete Pod
kubectl delete pod <Pod-Name>
kubectl delete pod my-first-pod

[참고 영상]

Udemy - Azure Kubernetes Service with Azure DevOps and Terraform

섹션 4 : Kubernetes Fundamentals with kubectl - Imperative Approach

22. Step-05 : Create a Pod, Understand about it and delete pod

 

[참고 문서]

https://github.com/stacksimplify/azure-aks-kubernetes-masterclass/tree/master/03-Kubernetes-Fundamentals-with-kubectl/03-01-PODs-with-kubectl