Kubectl 현재 컨텍스트 가져오기

Kubectl 현재 컨텍스트 가져오기

2022-06-03 last update

6 minutes reading Kubernetes
본고에서, 우리는kubectl가 현재 상하문을 가져오는 것을 토론할 것이다.It is used for viewing the config details of the current context. The beginners might not know what ‘current context’ refers to and what its functions are. This post will elaborate on the concept in detail. So, let’s start with learning the basics first and then going in-depth.

Kubectl 컨텍스트란 무엇입니까?

A kubectl context is basically a set of access parameters that contain a user, a namespace, and a cluster. A kubectl context is used to combine these sets of access parameters within an appropriate name. By default, the kubectl command line tool makes use of the above-mentioned parameters in order to communicate with the cluster.

Kubectl의 현재 환경은 무엇입니까?

The kubectl current context is the default cluster for kubectl, and all the commands of kubectl run against that cluster. When a cluster is created using a ‘gcloud container cluster create’ command, an automated entry is created with ‘kubeconfig’ in the user’s environment, and the current context will automatically change to that cluster.

선행 조건:

Before getting in-depth into kubectl to get the current context, let’s see what the essential prerequisites that need to be met are. Ubuntu 20.04 is used to run the kubectl commands, and the Minikube cluster is installed first before running any command in kubectl. Minikube makes it easier to run the kubernetes commands locally. It runs one node Kubernetes clusters within a VM to make it easy to design and develop for Kubernetes.

To start a minikube, all you need is a VM or a docker environment. Just enter the ‘minikube start’ command on any container or virtual machine manager, and you are good to go. Below is the output of the minikube start command:

Kubectl 컨텍스트 및 구성


Kubernetes는 Kubectl의 집단 인증 정보를 저장하기 위해 YAML 파일을 사용합니다. 이를 kubeconfig라고 합니다.이것은 명령을 실행하고 파일을 $HOME/에 저장할 때 인용하는 상하문 목록으로 구성되어 있습니다.기본적으로 kube/config입니다.
Kubectl config에서 Kubernetes 클러스터와 통신할 위치를 결정하고 구성 세부 정보를 수정합니다.아래kubectlconfigview 명령을 사용하는 코드를 참고하십시오.

단, 여러 개의kubeconfig 파일을 동시에 사용할 때 통합된 설정 상세 정보를 보려면 "kubeconfig=~/"를 사용하십시오.kube/설정: ~/."kube/kubeconfig2"명령을 사용합니다.다음 명령은 다음과 같습니다.

위 명령을 실행하면 "kubectl config view"명령을 실행하면 다음 출력이 생성됩니다.

Kubectl을 사용하여 사용자 암호를 구하는 방법은 무엇입니까?


"e2e"사용자의 암호를 가져오려면 다음 명령을 사용합니다.

이제 상술한 명령의 작업 원리를 점차적으로 이해하자.명령 jsonpath={.users[].name)}의 jsonpath 부분은 제공된 매개 변수에 따라 사용자 비밀번호를 표시합니다. 즉, 사용자 []는 어떤 내용도 포함하지 않기 때문에 첫 번째 사용자 비밀번호만 표시합니다.다음 참조 코드를 참조하십시오.

현재 사용자 암호 목록을 표시하려면 사용자에 * 를 매개 변수로 제공해야 합니다.jsonpath = "{.users[*].name)}"는 인자로 제공되기 때문에 사용자 암호 목록을 표시합니다.다음 참조 명령을 참조하십시오.

Kubectl 컨텍스트 목록은 어떻게 표시합니까?


get context 명령은 상하문 목록을 표시하는 데 사용됩니다."kubectl config get context"명령은 상하문 목록을 표시합니다.다음 kubectl 컨텍스트 목록을 참조하십시오.

Kubectl의 현재 배경은 어떻게 찾습니까?


Kubectl current context 명령은 Kubectl의 현재 컨텍스트를 표시합니다.가상 기기 환경에서 "kubectl config current context"를 입력하면 다음 출력이 표시됩니다.

"kubectl config use context cluster name"명령은 기본 상하문을 주어진 그룹 이름으로 설정하는 데 사용됩니다.
예를 들어 사용자는 그룹 이름을 minikube로 설정하기를 원한다.여기에서 그룹 이름은 minikube, 즉kubectlconfigusecontextminikube로 바뀝니다.이 명령을 실행하면 현재 상하문을 minikube로 전환합니다.다음 코드를 참조하십시오.

Set Credentials 명령을 사용하여 암호를 설정하는 방법은 무엇입니까?


kubectl config set credentials 명령은 기본 인증을 지원하는 새 사용자를 만드는 데 사용됩니다.kubectl config set credential 명령을 사용하면 사용자 이름과 비밀번호를 정의하여 인증 과정을 설정할 수 있습니다.setcredential 명령에 사용자 이름과 비밀번호를 제공하는 방법을 볼 수 있습니다.

Kubectl 구성 세트 컨텍스트란 무엇입니까?


kubectl 설정 집합 상하문은 이 상하문에서kubectl의 모든 명령을 영구적으로 저장하는 이름 공간입니다.kubectl config set context 명령은 이름 공간을 영구적으로 저장하는 데 사용됩니다.다음 코드를 참조하십시오.

또한 set context 명령은 특정 사용자 이름과 이름 공간을 사용하는 상하문을 설정하는 데 사용됩니다.다음 명령은 미니쿠브의 상하문을 gce로 변경합니다.

현재 상하문 명령을 실행하면 "gce"로 되돌아옵니다. set context 명령을 사용하여 현재 상하문을 "gce"로 설정하기 때문입니다.다음 출력을 참조하십시오.

Kubectl 구성이 설정되지 않은 것은 무엇입니까?


'kubectl config unset 명령'은kubeconfig 파일에서 지정한 인자를 설정하거나 삭제합니다.다음 명령은 사용자foo를 삭제하거나 다시 말하면 사용자foo 설정을 취소합니다.

Kubectl 구성의 별칭은 무엇에 사용됩니까?


별명은 대부분의 패턴이 하나의 단어bash 별명으로 압축될 수 있기 때문에 프로그래밍 속도를 높일 수 있다.다음 별칭을 정의하는 것은 다음에 상하문을 설정하거나 표시해야 할 때 상하문을 설정하거나 표시하기 위해서입니다.별명만 사용하면 다음 코드에서 "kx"입니다

"kx"에서 상하문을 설정한 후, 현재 명칭 공간을 설정하거나 표시할 수 있습니다"kn"설정 네임스페이스를 호출하기 전에 현재 상하문을 설정해야 합니다.단, 이 별명들은 bash나 bash와 호환되는 셸에만 사용할 수 있습니다.

결론:


kubectlcurrentcontext 명령은 현재 상하문에 대한 완전한 정보를 제공합니다.민쿠비 아니면 gce?본고는kubectlgetcurrentcontext를 상세하게 토론하였으며, 모든 명령에 예시를 제공하여 현재 context 명령의 기능을 더욱 잘 이해하도록 돕습니다.