본문 바로가기
Kubernetes

[k8s] yaml 정의 파일 빠르게 템플릿 생성

by Nhahan 2024. 7. 31.

 

  • --dry-run=client: 명령어 테스트용, 실제 자원 생성 안 함.
  • -o yaml: 자원 정의를 YAML 형식으로 출력.

 


 

예시)

 

- Pod

kubectl run nginx --image=nginx --dry-run=client -o yaml

 

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

 

 

- Deployment

kubectl create deployment --image=nginx nginx

 

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

 

 

- Service(ClusterIP)

kubectl expose pod redis --port=6379 --name redis-service --dry-run=client -o yaml

 

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    run: redis
  name: redis-service
spec:
  ports:
  - port: 6379
    protocol: TCP
    targetPort: 6379
  selector:
    run: redis
  type: ClusterIP
status:
  loadBalancer: {}

 

 

- Service(NodePort) / 외부 port 자동 설정

kubectl expose pod nginx --port=80 --name nginx-service --type=NodePort --dry-run=client -o yaml

 

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    run: nginx
  type: NodePort
status:
  loadBalancer: {}

 

 

 

- Service(NodePort) / 외부 port(30080) 수동 설정

kubectl create service nodeport nginx --tcp=80:80 --node-port=30080 --dry-run=client -o yaml

 

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: nginx
spec:
  ports:
  - name: 80-80
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30080
  selector:
    app: nginx
  type: NodePort
status:
  loadBalancer: {}

 

 

 

댓글