Pod 구성하는 YAML 파일 생성
# pod 생성하는 YAML 파일 생성
master@master:~$ cat jinsunginx.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
run: jinsunginx
name: jinsunginx
spec:
containers:
- name: nginx
image: nginx
master@master:~$
YAML 파일로 Pod 생성
# YAML 파일로 Pod 생성
master@master:~$ kubectl apply -f jinsunginx.yaml
pod/jinsunginx created
master@master:~$
# 생성한 Pod 확인
master@master:~$ kubectl get pod jinsunginx -oyaml
apiVersion: v1
kind: Pod
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"run":"jinsunginx"},"name":"jinsunginx","namespace":"default"},"spec":{"containers":[{"image":"nginx","name":"nginx"}]}}
creationTimestamp: "2022-08-07T06:26:05Z"
labels:
run: jinsunginx
name: jinsunginx
namespace: default
resourceVersion: "5061"
selfLink: /api/v1/namespaces/default/pods/jinsunginx
uid: 40941481-58b6-4684-8cce-7dd2dd84653b
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-g8wm6
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: master
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: default-token-g8wm6
secret:
defaultMode: 420
secretName: default-token-g8wm6
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2022-08-07T06:26:05Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2022-08-07T06:26:09Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2022-08-07T06:26:09Z"
status: "True"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2022-08-07T06:26:05Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://101279274be74990989e719696b2853cc3b5da4c382a78f4e738aa9bbb14f4e3
image: nginx:latest
imageID: docker-pullable://nginx@sha256:ecc068890de55a75f1a32cc8063e79f90f0b043d70c5fcf28f1713395a4b3d49
lastState: {}
name: nginx
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2022-08-07T06:26:09Z"
hostIP: 192.168.0.201
phase: Running
podIP: 10.42.0.6
podIPs:
- ip: 10.42.0.6
qosClass: BestEffort
startTime: "2022-08-07T06:26:05Z"
master@master:~$
Kubectl run명령으로 yaml 파일 생성
- 커맨드는 서비스에 대한 구성을 생성하지만, 이를 kube-apiserver에 전송하는 대신 YAML 형식으로 stdout에 출력한다.
kubectl run redis --image=redis --dry-run=client -o yaml > redis.yaml
cat redis.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: redis
name: redis
spec:
containers:
- image: redis
name: redis
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
즉석 리소스 생성
# 즉시 리소스 생성
master@master:~$ cat << EOF | kubectl apply -f -
> apiVersion: v1
> kind: Pod
> metadata:
> labels:
> run: jinsunginx
> name: jinsunginx
> spec:
> containers:
> - name: nginx
> image: nginx
> ports:
> - containerPort: 80
> EOF
pod/jinsunginx created
master@master:~$
# 상태 확인
master@master:~$ kubectl get pod
NAME READY STATUS RESTARTS AGE
jinsunginx 1/1 Running 0 15s
master@master:~$ kubectl get pod jinsunginx -oyaml
apiVersion: v1
kind: Pod
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"labels":{"run":"jinsunginx"},"name":"jinsunginx","namespace":"default"},"spec":{"containers":[{"image":"nginx","name":"nginx","ports":[{"containerPort":80}]}]}}
creationTimestamp: "2022-08-07T07:03:01Z"
labels:
run: jinsunginx
name: jinsunginx
namespace: default
resourceVersion: "6649"
selfLink: /api/v1/namespaces/default/pods/jinsunginx
uid: fd90af8b-8d3d-40fb-bd3c-7ac553728cc5
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-g8wm6
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: master
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: default-token-g8wm6
secret:
defaultMode: 420
secretName: default-token-g8wm6
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2022-08-07T07:03:01Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2022-08-07T07:03:06Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2022-08-07T07:03:06Z"
status: "True"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2022-08-07T07:03:01Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://aeab365d5f8ea73911e2218105f0194825748ae244cd377a718e68d78cae7557
image: nginx:latest
imageID: docker-pullable://nginx@sha256:ecc068890de55a75f1a32cc8063e79f90f0b043d70c5fcf28f1713395a4b3d49
lastState: {}
name: nginx
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2022-08-07T07:03:05Z"
hostIP: 192.168.0.201
phase: Running
podIP: 10.42.0.8
podIPs:
- ip: 10.42.0.8
qosClass: BestEffort
startTime: "2022-08-07T07:03:01Z"
master@master:~$
'Kubernetes' 카테고리의 다른 글
[K8S] 쿠버네티스 - 볼륨(volume) (0) | 2022.08.07 |
---|---|
[K8S] 쿠버네티스 - 라벨(label), 셀렉터 시스템 (0) | 2022.08.07 |
[K8S] 쿠버네티스 - k3s 구성 (0) | 2022.08.07 |
[K8S] 쿠버네티스 - k3s 명령어 (0) | 2022.08.07 |
[K8S] 쿠버네티스 - Pod 구성 (0) | 2022.08.07 |