Mock Exam - 3
Introduction
뭄샤드 kode kloud - mock exam 3
Summary
export samp="--dry-run=client -o yaml"
export now="--force --grace-period 0"
$samp, $now붙은건 이 명령어로 약어만든거니까 주의
Kubectl Reference Docs
kubernetes.io
# 1
서비스 어카운트를 만들고
클러스터롤과 클러스터롤바인딩을 만들으라고함.
이 서비스 어카운트를 클러스터롤과 연결시키라는 문제임.
- 먼저 service account 부터.
kubectl create sa pvviewer
커맨드는 이렇고
apiVersion: v1
kind: ServiceAccount
metadata:
creationTimestamp: null
name: pvviewer
야믈은 이렇게 생김.
- 다음으로 clusterrole을 만들자.
kubectl create clusterrole pvviewer-role --verb list --resource pv
커맨드라인. verb에 권한종류들어가고 resource에 pod pv이런 리소스 들어
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: pvviewer-role
rules:
- apiGroups:
- ""
resources:
- persistentvolumes
verbs:
- list
잘만들어짐
- clusterrolebinding을 만들자
kubectl create clusterrolebinding pvviewer-role-binding --serviceaccount default:pvviewer --clusterrole pvviewer-role
커맨드상으로
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
creationTimestamp: null
name: pvviewer-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: pvviewer-role
subjects:
- kind: ServiceAccount
name: pvviewer
namespace: default
yaml
잘됐음
- 확인방법
kubectl auth can-i list pv --as=system:serviceaccount:default:pvviewe
사실 이 명령어 모른채로 시험봤음.. 근데 알면 좋겠지?
- 이제 이 service account랑 pod랑 연결하자~
Configure Service Accounts for Pods
Kubernetes offers two distinct ways for clients that run within your cluster, or that otherwise have a relationship to your cluster's control plane to authenticate to the API server. A service account provides an identity for processes that run in a Pod, a
kubernetes.io
여기서 kind: pod로 검색
이것처럼 spec필드에 serviceAccountName필드 추가하면 댐
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: pvviewer
name: pvviewer
spec:
containers:
- image: redis
name: pvviewer
serviceAccountName: pvviewer
pod가 service account잘 쓰구있음
role & rolebinding / clusterRole & clusterRolebinding / service account
Introductionrole과 rolebinding에 대해서 개념을 잡고가기 위해 최대한 간추려서 써봄 Summaryuser와 role은 연결되기 위해 rolebinding이라는 리소스를 만듦role과 clusterrole차이는 namespace차이service account는 pod
jacobowl.tistory.com
여기 정리해놨움
# 2 안풀어도댐!
노드의 인터널 아이피 구해서 파일에 양식대로 넣으라는거임
이거 안풀어도됨.
걍 대충 풀이법만 쓰자면
노드 -o wide로 검색하면 저리 나옴. 저거 스트링으로 걍파일에 넣음댐.
솔루션은 jsonpath로 풀었던걸로 기억함..
# 3
멀티 컨테이너 파드 문제임
커맨드로는 멀티컨테이너 넣을 수 없으니 야믈만 따보자.
kubectl run multi-pod --image busybox --env name=beta $samp --command -- sleep 4800 > 3.yaml
커맨드 필드 따로 가져오기싫어서 beta컨테이너 기준으로 만들음
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: multi-pod
name: multi-pod
spec:
containers:
- command:
- sleep
- "4800"
env:
- name: name
value: beta
image: busybox
name: multi-pod
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
이렇게 나옴. 여기서 containers필드에 어레이요소 하나 더 추가하면
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: multi-pod
name: multi-pod
spec:
containers:
- command:
- sleep
- "4800"
env:
- name: name
value: beta
image: busybox
name: beta
- env:
- name: name
value: alpha
image: nginx
name: alpha
참고로 multi-pod라고 지어진 컨테이너 이름도 조건에 맞게 바꾸샘
자동으로 pod이름으로 지어진거니까..
잘만들어짐
컨테이너 세세히 보고 싶으면 describe로 확인하샘
따배씨 / pod - multi & side-car & init containers / resource usage
Introductionpod는 거의다 아는데 문제유형 훝고 몰랐던 자잘한거 정리하는 용도로 포스팅함.강의 여섯개인가 내용 싹다 걍 합쳐서 제목이 좀 괴랄하다.Summary리소스만들때 먼저 dry-run해주고 문제랑
jacobowl.tistory.com
멀티 pod 포스팅임
# 4 안풀어도댐!
저런 조건의 pod를 만들라는데 CKA에 안나온다.
난 걍 공식문제 뒤져서 풀긴함.
Configure a Security Context for a Pod or Container
A security context defines privilege and access control settings for a Pod or Container. Security context settings include, but are not limited to: Discretionary Access Control: Permission to access an object, like a file, is based on user ID (UID) and gro
kubernetes.io
여기서 fsgroup으로 검색해서
저옵션 맞게 넣어주면댐. 그래도 맞긴했음.
사실 개념도 모름. 나중에 k8s공부 더 하면 알게되겠지?
# 5
트러블 슈팅나오고 트러블슈팅인가 했고 인그레스 나와서 인그레스만드는건가 헀는데 network policy문제임
pod는 nginx임. 포트 80이겠지?
해당 pod에 curl을 쳐봤는데 안됨
서비스도 안됨.
network policy검색해보니 기본거부하는 정책이 있음.
network policy는 ns기준으로 동작함. 그럼 해당 pod만 뚫어주자.
Network Policies
If you want to control traffic flow at the IP address or port level (OSI layer 3 or 4), NetworkPolicies allow you to specify rules for traffic flow within your cluster, and also between Pods and the outside world. Your cluster must use a network plugin tha
kubernetes.io
공식문서임
이렇게 생김.
그럼 저 pod들만 뚫어주는걸 어떻게 해주까?
문제에서 80번포트 뚫어주라고함.
1. pod selector에 라벨링 확인해서 적어주자.
run=np-test-1이 있음
이거 spec.podSelector.matchLabels에 적으면댐
2. ingress만 하면댄다. 모든 트래픽!
다만 포트는 80번만!
spec.ingress쪽에 port에 적으면 댐.
둘다 적용하면
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: ingress-to-nptest
namespace: default
spec:
podSelector:
matchLabels:
run: np-test-1
policyTypes:
- Ingress
ingress:
- from: {}
ports:
- protocol: TCP
port: 80
저 부분들 수정해줌
사실 시발 저기 run부분을 role로 그대로 남겨놔서 계속 검토함 ㅠ 시험볼떄는 수시로 확인 잘하샘
svc랑 pod아이피로 curl치니까 이제 잘댐
따배씨 / network policy
Introductionㅇㅇ ## network policy란?서로 통신 규약 만들어주는거임 ## 공식문서 & yaml양식 Network PoliciesIf you want to control traffic flow at the IP address or port level (OSI layer 3 or 4), NetworkPolicies allow you to specif
jacobowl.tistory.com
이거 내 network policy포스팅임
# 6
taint로 스케줄링 관리하는 문제
Taints and Tolerations
Node affinity is a property of Pods that attracts them to a set of nodes (either as a preference or a hard requirement). Taints are the opposite -- they allow a node to repel a set of pods. Tolerations are applied to pods. Tolerations allow the scheduler t
kubernetes.io
저 명령어로 해주자.
먼저 taint 를 해주자.
node01에 taint잘됐따.
일단 문제에서 value=production이 있는건 node01에 스케줄링이 될거임.
dev-redis pod는 node01에 스케줄링 안되야하니까 그냥만들면댐
kubectl run dev-redis --image redis:alpine
커맨드
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: dev-redis
name: dev-redis
spec:
containers:
- image: redis:alpine
name: dev-redis
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
pod를 만들어보니 node01이 아닌 controlplane 노드에 잘 만들어진걸 볼 수 있음.
이제 prod-redis를 만들어줄건데 해당 pod에 toleration필드 만들어서 설정하면댐.
아까 공식문서에서 kind: pod검색 ㄱ
이거뜨는데 저기 spec.toleration부분에 exist라서 좀 스크롤 올리면
이거있음. 이거 equal로 바꿔서 쓰자. exist는 해당 키값 존재만 체크하고 equal은 값도 체크하는거임
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: prod-redis
name: prod-redis
spec:
containers:
- image: redis:alpine
name: prod-redis
tolerations:
- key: "env_type"
operator: "Equal"
effect: "NoSchedule"
value: "production"
문제에서 원하는대로 dev-redis는 node01에 안생겼고
prod-redis는 node01에 생겼따
따배씨 / node selector, drain, taint
Introductionnode에 관련한 명령어들과 CKA에 나오는 문제유형을 써보겠음.일단 advanced라 유료결제안했었고 명령어들이 쎄보여서 어려울줄알았는데 pod만드는것보다 쉬운것같음.따배씨에서 강의 세
jacobowl.tistory.com
따배씨 내용인데 내가 집중해서 안들었는지 몰라도 taint 키벨류값이 있고없고 차이는 설명이 없던거같다.
때문에 포스팅도 단순히 왜 controplane에 pod가 안생기냐 헀던거임.
이거 라벨링처럼 이해하면 잘 풀수 있음.
# 7
라벨링문제임 개쉬움
kubectl run hr-pod -n hr --labels environment=production,tier=frontend --image redis:alpine
이거 한줄이면 끝임
근데 ns가 없음.
kubectl create ns hr
ns만들어주고 다시하면
잘만들어짐.
참고로 난 이거 처음풀때 env만드는건줄알고 컨테이너안에 환경변수로 만들어서 틀림 ㅋ
# 8 안풀어도댐!
솔찍히 kubeconfig파일 뒤지는거모름.
cka에 안나오니까 풀지마샘
# 9 안풀어도댐!
이거도 풀지마샘. scale하면 컨트롤러가 컨테이너 늘려줘야하는데 제대로 동작안함.
난 어찌저찌 kube system쪽 컨트롤런가 스케줄런가 만져서 풀었는데 이런문제 안나옴.
풀지마샘