CKA를 준비하며..
kubectl get pods
kubectl run nginx --image={imgname}
kubectl describe pod {podname}
kubectl delete pod {podname}
kubectl create -f {yamlfile}
kubectl run redis --image=redis123 --dry-run=client -o yaml > redis-definition.yaml
kubectl apply -f redis-definition.yaml
kubectl get replicasets
kubectl get rs
kubectl create -f ./replicaset-definition-1.yaml
kubectl apply -f /root/replicaset-definition-2.yaml
kubectl delete rs replicaset-1
replicaset의 selector의 matchlabels의 tier와 template - label - tier가 일치해야한다.
kubectl get all
Create an NGINX Pod
kubectl run nginx --image=nginx
Generate POD Manifest YAML file (-o yaml). Don't create it(--dry-run)
kubectl run nginx --image=nginx --dry-run=client -o yaml
Create a deployment
kubectl create deployment --image=nginx nginx
Generate Deployment YAML file (-o yaml). Don't create it(--dry-run)
kubectl create deployment --image=nginx nginx --dry-run=client -o yaml
Generate Deployment YAML file (-o yaml). Don't create it(--dry-run) with 4 Replicas (--replicas=4)
kubectl create deployment --image=nginx nginx --dry-run=client -o yaml > nginx-deployment.yaml
Save it to a file, make necessary changes to the file (for example, adding more replicas) and then create the deployment.
kubectl create -f nginx-deployment.yaml
OR
In k8s version 1.19+, we can specify the --replicas option to create a deployment with 4 replicas.
kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30008
kubectl get services
type: ClusterIP
ports:
- targetPort: 80
port: 80
selector:
app: myapp
type: back-end
kubectl create -f pod-definition.yml --namespace=dev
이렇게 실행해줘도 되고 yaml파일 내에 metatadata 아래로 옮겨줘도 된다.kubectl create namespace dev / kubectl create -f namespace-dev.yml
kubectl get pods - -all namespaces
kubectl config set-context $(kubectl config current-context) - -namespace=dev
imperative: 어떻게 할지를 묘사. ↔ Declative: 무엇을 할지를 선언
imperative : run, create, expose, edit … yaml file 건들지 않고 직접 선언해주기
edit은 k8s 메모리 상의 definition 파일을 수정할 뿐, 로컬은 그대로다. 로컬에 반영하려면
kubectl replace -f nginx.yaml
kubectl replace —force -f nginx.yaml
declative
kubectl apply -f nginx.yaml
tip
--dry-run=client
→ test용-o yaml
→ yaml 형식으로 output 생성