YAML 파일은 object를 만들거나 Pod's replicas, deployment 서비스 등 모든곳에서 사용합니다.
쿠버네티스에서 yaml파일을 사용하기위해서 기본적으로 필요한 것이 있다(apiVersion, kind, metadata, spec)
apiVersion:
kind:
metadata:
spec:
apiVersion : 쿠버네티스의 api 버전을 이야기 한다.
kind : 무엇을 만들것인지 를 정함(POD, Service, ReplicaSet, Deployment)
metadata: 리소스의 이름, Label 등을 지정 한다.
spec: 생성하고자 하는 리소스들의 종류나 타입들에 따라서 다르다.
아래에서는 테스트로 싱글 pod에 2개의 Container를 만들어 보겠습니다.
#1pod_2container.yml
apiVersion: v1
kind: Pod #string
metadata:
name: 1pod-2container
labels: # dictionary
app: ubuntu-nginx
spec:
containers:
- name: nginx-container
image: nginx
- image: ubuntu
name: ubuntu
command: ["/bin/sh"]
args: ["-c", "while true; do echo hello; sleep 10;done"]
# Docker 에서는 command에 인자값을 줄때 Cmd를 사용했지만 Kubernetes에서는 arg를 사용한다.
yaml 파일을 다 작성 했으면 kuberctl create를 사용하여 pod을 생성해보겠습니다.
kubectl create -f 1pod-2container.yml
kubectl get pods 을 통해 만들어진 Pod을 확인할수 있고 kubectl describe pod myapp-pod로 자세한 설명을 볼수 있다.
KDS-2:yaml kimdaesung$ kubectl get pods
NAME READY STATUS RESTARTS AGE
1pod-2container 0/2 ContainerCreating 0 8s
KDS-2:yaml kimdaesung$ kubectl describe pod 1pod-2container
Name: 1pod-2container
Namespace: default
Priority: 0
Node: m01/192.168.99.100
Start Time: Sun, 22 Mar 2020 17:54:46 +0900
Labels: name=ubuntu-nginx
Annotations: <none>
Status: Running
IP: 172.17.0.4
IPs:
IP: 172.17.0.4
Containers:
ubuntu:
Container ID: docker://5598b16f73ad58705520efd472c36d491f6658523440b5f5478a8dc2a3ab9242
Image: ubuntu
Image ID: docker-pullable://ubuntu@sha256:bec5a2727be7fff3d308193cfde3491f8fba1a2ba392b7546b43a051853a341d
Port: <none>
Host Port: <none>
Command:
/bin/sh
Args:
-c
while true; do echo hello; sleep 10;done
State: Running
Started: Sun, 22 Mar 2020 17:54:55 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-rs2h4 (ro)
nginx-container:
Container ID: docker://f6a18a3c9b29caf925d30b605ef8590309af712a22a7a18b87bcf5979aa012aa
Image: nginx
Image ID: docker-pullable://nginx@sha256:2539d4344dd18e1df02be842ffc435f8e1f699cfc55516e2cf2cb16b7a9aea0b
Port: <none>
Host Port: <none>
State: Running
Started: Sun, 22 Mar 2020 17:55:06 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-rs2h4 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-rs2h4:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-rs2h4
Optional: false
QoS Class: BestEffort
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 61s default-scheduler Successfully assigned default/1pod-2container to m01
Normal Pulling 61s kubelet, m01 Pulling image "ubuntu"
Normal Pulled 52s kubelet, m01 Successfully pulled image "ubuntu"
Normal Created 52s kubelet, m01 Created container ubuntu
Normal Started 52s kubelet, m01 Started container ubuntu
Normal Pulling 52s kubelet, m01 Pulling image "nginx"
Normal Pulled 41s kubelet, m01 Successfully pulled image "nginx"
Normal Created 41s kubelet, m01 Created container nginx-container
Normal Started 41s kubelet, m01 Started container nginx-container
'Kubernetes' 카테고리의 다른 글
쿠버네티스 기초 ReplicaSet (0) | 2020.03.27 |
---|---|
쿠버네티스 기초 Replication Controller (0) | 2020.03.26 |
쿠버네티스 기초 Pods (0) | 2020.03.20 |
kubectl autocomplete 설정하기 (0) | 2020.03.18 |
Minikube tutorial (0) | 2020.03.17 |