실험환경
1.
vmware로 저번에 만든 master를 실행함
2.
window pc
server1@master:~$ mkdir yaml
server1@master:~$ cd yaml/
server1@master:~/yaml$ gedit go-http-pod.yaml
server1@master:~/yaml$ kubectl create -f go-http-pod.yaml
pod/http-go created
server1@master:~/yaml$ ^C
server1@master:~/yaml$
YAML
복사
•
mkdir yaml : yaml 이라는 이름의 파일 생성
•
cd yaml : yaml 폴더 안에 들어가기
•
gedit go-http-pod.yaml : go-http-pod.yaml 파일을 생성하고 편집기 실행
•
go-http-pod.yaml 파일내용은 다음과 같다.
apiVersion: v1
kind: Pod
metadata:
name: http-go
spec:
containers:
- name: http-go
image: gasbugs/htttp-go
ports:
- containerPort: 80
YAML
복사
•
metadata:
name: http-go 의 의미는 pod 의 이름이 http-go 이다.
•
containers:
- name: http-go 의 의미는 컨테이너의 이름이 http-go이다. (pod이름과 동일해도 상관없음)
•
image: gasbugs/http-go 의 의미는 gasbugs/htttp-go를 실행하는 것이다. (ex : image: nginx:1.14.2)
•
kubectl create -f go-http-pod.yaml 의 의미는 우리가 만든 yaml 파일을 실행하는 것이다.
다음단계
•
pod 조회
◦
kubectl get pod [pod 이름]
◦
예시
server1@master:~/yaml$ kubectl get pod http-go
NAME READY STATUS RESTARTS AGE
http-go 0/1 Pending 0 10s
server1@master:~/yaml
YAML
복사
•
정확한 pod 조회
◦
kubectl get pod http-go -o wide
server1@master:~/yaml$ kubectl get pod http-go -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-go 0/1 Pending 0 2m51s <none> <none> <none> <none>
server1@master:~/yaml$
YAML
복사
•
pod의 자세한 내용을 yaml로 보려고 할때
server1@master:~/yaml$ kubectl get pod http-go -o yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2021-11-10T11:09:10Z"
name: http-go
namespace: default
resourceVersion: "339367"
uid: b3eb308b-a4ac-4215-85de-e2cc17025e06
spec:
containers:
- image: gasbugs/htttp-go
imagePullPolicy: Always
name: http-go
ports:
- containerPort: 80
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-b8fq6
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
preemptionPolicy: PreemptLowerPriority
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: kube-api-access-b8fq6
projected:
defaultMode: 420
sources:
- serviceAccountToken:
expirationSeconds: 3607
path: token
- configMap:
items:
- key: ca.crt
path: ca.crt
name: kube-root-ca.crt
- downwardAPI:
items:
- fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
path: namespace
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2021-11-10T11:09:10Z"
message: '0/3 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master:
}, that the pod didn''t tolerate, 2 node(s) had taint {node.kubernetes.io/unreachable:
}, that the pod didn''t tolerate.'
reason: Unschedulable
status: "False"
type: PodScheduled
phase: Pending
qosClass: BestEffort
server1@master:~/yaml$
YAML
복사
•
kubectl describe pod http-go
server1@master:~/yaml$ kubectl describe pod http-go
Name: http-go
Namespace: default
Priority: 0
Node: <none>
Labels: <none>
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Containers:
http-go:
Image: gasbugs/htttp-go
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-b8fq6 (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
kube-api-access-b8fq6:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 24s (x11 over 10m) default-scheduler 0/3 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 2 node(s) had taint {node.kubernetes.io/unreachable: }, that the pod didn't tolerate.
server1@master:~/yaml$
YAML
복사
•
컨테이너에서 호스트로 포트포워딩
•
kubectl port-forward http-go 8080 :8080
server1@master:~/yaml$ kubectl port-forward http-go 8080 :8080
error: unable to forward port because pod is not running. Current status=Pending
server1@master:~/yaml$
YAML
복사
•
Pending 상태라서 일단 다른 예제로 한번 또 해보겠음
또다른 예제
•
gedit nginx-glory.yaml 입력
server1@master:~/yaml$ gedit nginx-glory.yaml
server1@master:~/yaml$
YAML
복사
•
아래의 yaml 소스 넣기 (nginx 예제)
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
YAML
복사
•
kubectl create -f nginx-glory.yaml 입력
•
kubectl get pod nginx
server1@master:~/yaml$ gedit nginx-glory.yaml
server1@master:~/yaml$ kubectl create -f nginx-glory.yaml
pod/nginx created
server1@master:~/yaml$ kubectl get pod nginx
NAME READY STATUS RESTARTS AGE
nginx 0/1 Pending 0 56s
server1@master:~/yaml$
YAML
복사
•
어? 이것도 pending이 뜨네
•
네트워크 상에 문제가 있는것 같은데 describe 로 원인을 찾아보도록 하겠다