- --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: {}
728x90
'Kubernetes' 카테고리의 다른 글
[k8s] pod의 env가 ConfigMap 참조하도록 설정 (0) | 2024.08.18 |
---|---|
[k8s] 생성된 리소스의 .yaml 보기 (or copy) (0) | 2024.08.18 |
[k8s] kubectl, minikube 세팅 (0) | 2024.07.18 |
[k8s] pod practice (0) | 2024.07.18 |
[k8s] Kubernetes Architecture (0) | 2024.07.08 |
댓글