본문 바로가기
IT 기술/Infra

[CKA] k8s - 공부요약

by Geunny 2024. 2. 9.
반응형

kubectl 사용하기

 

kubectl 자동완성 설정 및 k alias 설정하기.

 

https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#optional-kubectl-configurations-and-plugins

 

Install and Set Up kubectl on Linux

Before you begin You must use a kubectl version that is within one minor version difference of your cluster. For example, a v1.29 client can communicate with v1.28, v1.29, and v1.30 control planes. Using the latest compatible version of kubectl helps avoid

kubernetes.io

 

kubectl 기본 사용법

# pod 확인
k get pods

# k8s 모든 pod 확인 (Controller 관련 pod 모두 출력)
k get pods -A

# replicaset 확인
k get replicasets

# deployments 확인

k get deployment

# 각 오브젝트 삭제방법
# ObjectType ex) pod, replicaset, deployment, service etc..
k delete {$ObjectType} {$ObjectName}

# 변경기록 방법 --record 추가
k create -f deployment-start.yaml --record

 

 

서비스 생성

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  type: NodePort # 포트포워딩 역할의 Service
  ports:
    - port: 80 # 현재 클러스터의 포트
      targetPort: 80 # 배포된 pod 의 포트
      nodePort: 30004 # 외부로 노출되는 포트 ex) 외부(웹/앱) 에서 접근시 {클러스터IP}:30004 포트로 접속
  selector:
    app: myapp # 사용중인 deployment 또는 replicasets 의 label 값

댓글