반응형
문제 1번
- Create a static pod on node1 called mydb with image redis.
- user /etc/kubernetest/manifaests as the static pod path for example
- kubelet configured for static pods
- pod mydb-node1 is up and running
- Create this pod on node1 and make sure that it is recreated/restarted automatically in case of a failure
필요한 조건 : redis image, static pod, livenessprobe
풀이 1
node1으로 이용해서 staticPodPath를 확인
cat /var/lib/kubelet/config.yaml | grep staticPodPath
풀이 2
문제에서 제시한 위치와 동일하므로 해당 위치로 이동
cd /etc/kubernetest/manifaests
풀이 3
yaml 파일 생성
apiVersion: v1
kind: Pod
metadata:
name: mydb
spec:
containers:
- name: redis-container
image: redis:alpine
ports:
- containerPort: 6379
protocol: TCP
livenessProbe:
exec:
command:
- redis-cli
initialDelaySeconds: 10
timeoutSeconds: 5
staticPodPath에 yaml파일을 생성하면 파드 생성 명령어를 따로 입력하지 않아도 바로 생성이된다.
※ yaml 파일 작성시 오타와 tab에 주의!
yaml 파일에는 pod 이름을 mydb로 설정해주었지만 생성되는 pod name은 노드에 이름이 붙은 mydb-node1이다.
master node에서 describe를 통해 잘 생성되었는지 확인할 수 있다.
kubectl get pods
kubectl describe pod mydb-node1
문제 2번
다음과 같은 조건에 맞는 pod를 생성하시오
- cpu 200m, memory 500mi request, cpu1core memory 1Gi limits
- namespace product에서 동작
- application 동작에 필요한 환경변수 DB=mydb를 포함
- pod name : myweb, image: nginx:1.14
풀이 1
네임스페이스를 생성한다.
현재 존재하는 네임스페이스 조회
kubectl get namespace
product 네임스페이스 생성
kubectl create namespace product
풀이 2
matser node에서 yaml 파일 생성
metadata에 namespace를 정의해준다.
apiVersion: v1
kind: Pod
metadata:
name: myweb
namespace: product
spec:
containers:
- name: myweb-nginx
image: nginx:1.14
ports:
- containerPort: 80
protocol: TCP
resources:
requests:
cpu: 200m
memory: 500Mi
limits:
cpu: 1
memory: 1Gi
env:
- name: DB
value: "mydb"
풀이 3
pod 생성 후 확인
pod 생성
kubectl create -f filename.yaml
product namespace에 pod 확인
kubectl get pods -n product
describe로 확인
kubectl describe --namespace=product pod myweb
환경변수를 확인하는 또 다른 방법 : 컨테이너에 들어가서 출력해보기
kubectl exec --namespace=product myweb -it -- /bin/bash
echo $DB
반응형
'Kubernetes' 카테고리의 다른 글
[Kubernetes] VM 쿠버네티스 실습환경 설정 - kubectl 설치 (0) | 2023.04.07 |
---|---|
[Kubernetes][따배쿠 6-1] Controller - Replication Controller (0) | 2023.03.22 |
[Kubernetes] pod에 resource 할당하기 | 환경변수 설정과 실행 패턴 (0) | 2023.03.17 |
[Kubernetes] init & infra container / static pod (0) | 2023.03.03 |
[Kubernetes] LivenessProbe : Self-healing Pod (0) | 2023.02.23 |