PaaS/Kubernetes

(Kubernetes) 쿠버네티스 기초 학습

armyost 2021. 3. 10. 23:03
728x90

kubectl cluster-info

  • Let’s view the cluster details. We’ll do that by running kubectl cluster-info

kubectl get nodes

  • To view the nodes in the cluster, run the kubectl get nodes command:

kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

  • deploy our first app on Kubernetes

kubectl get deployments

  • To list your deployments

kubectl proxy

  • 쿠버네티스에서, 노드, 파드 및 서비스는 모두 고유한 IP를 가진다. 대부분의 경우, 클러스터의 노드 IP, 파드 IP 및 일부 서비스 IP는 라우팅할 수 없으므로, 데스크톱 시스템과 같은 클러스터 외부 시스템에서 도달할 수 없다.
    연결하는 방법.
    클러스터 외부에서 노드, 파드 및 서비스에 연결하기 위한 몇 가지 옵션이 있다. 프록시 작업(Proxy Verb)을 사용하여 서비스, 노드 또는 파드에 접근한다.

kubectl get pods

  • We’ll use the kubectl get command and look for existing Pods:

kubectl describe pods

  • to view what containers are inside that Pod and what images are used to build those containers

kubectl logs $POD_NAME

  • We can retrieve these logs using the kubectl logs command

kubectl exec -ti $POD_NAME bash

  • Next let’s start a bash session in the Pod’s container

kubectl get services -l run=kubernetes-bootcamp

  • Pod의 경우에 지정되는 Ip가 랜덤하게 지정이 되고 리스타트 때마다 변하기 때문에 고정된 엔드포인트로 호출이 어렵다, 또한 여러 Pod에 같은 애플리케이션을 운용할 경우 이 Pod 간의 로드밸런싱을 지원해줘야 하는데, 서비스가 이러한 역할을 한다.서비스는 지정된 IP로 생성이 가능하고, 여러 Pod를 묶어서 로드 밸런싱이 가능하며, 고유한 DNS 이름을 가질 수 있다.

kubectl label pod $POD_NAME app=v1

  • To apply a new label we use the label command followed by the object type, object name and the new label:

kubectl delete service -l run=kubernetes-bootcamp

  • To delete Services

kubectl get rs

  • To see the ReplicaSet created by the Deployment

kubectl scale deployments/kubernetes-bootcamp --replicas=4

  • let’s scale the Deployment to 4 replicas

kubectl scale deployments/kubernetes-bootcamp --replicas=2

  • To scale down the Service to 2 replicas

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2

  • To update the image of the application to version 2

kubectl rollout status deployments/kubernetes-bootcamp

  • The update can be confirmed also by running a rollout status command

kubectl rollout undo deployments/kubernetes-bootcamp

  • Let’s roll back to our previously working version.