인프런

Kubernetes 설치 및 기본 명령어

date
Mar 25, 2025
slug
CI-CD-Pipeline-with-Jenkins-5
status
Public
tags
Jenkins를 이용한 CI/CD Pipeline 구축
author
summary
쿠버네티스 설치
type
Post
thumbnail
updatedAt
Mar 26, 2025 03:24 AM
category
인프런

📝 강의 정리


[1]. Kubernetes(Minikube) 설치( M1 mac )


Minikube?

  • 테스트용 쿠버네티스
  • 단일 노드로 작동한다
 
  1. Extensions > Settings 들어가기
notion image
  1. kubernetes > Enable Kubernetes
notion image
  • 체크하고 apply & restart 하면 install
 

k8s 기본 명령어


  • kubectl get nodes
  • kubectl get pods
  • kubectl get deployments
  • kubectl get services
  • kubectl delete pod/ pod명

k8s로 nginx를 80포트로 실행시키기

  • kubectl run sample-nginx --image=nginx --port=80
 

실행중인 nginx의 스펙을 보려면

  • kubectl desribe pod/[pod name]
notion image
  • container, image, network 등의 정보를 볼 수 있다.
  • 하단의 events 를 통해 활동 로그도 확인 가능
 

nginx를 deployment 로 실행

  • kubectl create deployment [deployment 명] --image=[base-image]
  • 실행 중인 pod를 조회하면 deployment-난수 의 형식으로 실행중인 pod를 확인할 수 있다.
    • notion image
  • 이 때, 실수로 해당 pod를 지웠다고 가정해보면
    • notion image
      delete 명령어 이후 새로운 난수를 가진 pod가 생성되었음을 확인할 수 있다.
      → deployment는 유지하려고 하는 최소한의 pod 개수를 유지해준다.

deployment의 스케일 확장

  • deployment의 pod 개수를 확장해보자
    • kubectl scale deployment [deployment명] --replicas=[개수]
      notion image
  • sample-nginx의 pod가 2개로 늘어난 것을 확인할 수 있다.
 

k8s script

  • kubectl 명렁어가 아닌 스크립트를 통해 제어해보자
    • # scripts.xml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
  • apiVersion: 일반적으로 많이 사용하는 pod, deployment, service의 경우 apps/v1을 많이 사용한다.
  • kind: 만들고자 하는 k8s Object
  • metadata: 현재 작성된 스크립트의 정보
  • spec: k8s object에 따라 종류가 달라진다.
    • 위 예제에선 2개의 pod를 유지
    • 레이블은 nginx
    • base image가 nginx 컨테이너를 80번 포트로 실행
 

📎 출처