This article is not available in English, view it in Korean

I am a Developer.

Print


Developers develop applications using source repositories, builds and deployments, Image Registry, etc.

Using the kubectl Command

Kubectl is a command that connects to Kubernetes and performs various operations such as deploying and configuring applications.

This document guides you through the binary installation process in a Windows environment.

Please refer to the official website below for instructions on installing kubectl for each environment.


Please refer to the instructions below for installation procedures and detailed steps.

  1. Create a directory to store kubectl files
  2. Download the kubectl executable
  3. Download the configuration file for setting up Kubernetes connection
  4. Setting global environment variables
    1. Add kubectl executable path to PATH setting
    2. Registering the environment settings file as a global environment variable


Follow along

Create a directory to store kubectl files

Create a directory (folder) to store the executable file by running Windows Explorer.

  • channel
    • C:\kube


Download the kubectl executable

Download the kubectl.exe executable file using the link below to the c:\kube folder you initially created.


Open a cmd window and navigate to the c:\kube folder and check the kubectl version command.

c:\> cd c:\kube c:\kube> kubectl version Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T21:04:45Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"windows/amd64"} 
# 서버 연결설정이 되어 있지 않으면 아래와 같이 오류 메시지가 발생 Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

Download the configuration file for setting up Kubernetes connection

To connect using kubectl installed on a ZCP cluster, you need related settings such as cluster server information and authentication token. These values are managed in the Kubernetes configuration file.

These connection settings can be downloaded from the CloudZ CP console. Click on your username in the upper right corner and select CLI Command from the drop-down list.

On the CLI Command screen, click the Download button in step 2. Change the file name to kube.conf and download it to the c:\kube folder.


To execute kubectl commands using the downloaded kube.conf file, you can use the command as follows:

c:\> cd c:\kube 
# 설정 파일 사용 여부 설정 c:\kube> set KUBECONFIG=c:\kube\kube.conf 
c:\kube> kubectl version Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T21:04:45Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"windows/amd64"} 
# 서버 연결이 되면 아래 서버 버전 정보가 표시됩니다. Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.10+IKS", GitCommit:"7b8624d43d0e5341ae55537998cddb865607059c", GitTreeState:"clean", BuildDate:"2019-05-08T19:47:50Z", GoVersion:"go1.10.8", Compiler:"gc", Platform:"linux/amd64"}


To enable it, run the command set KUBECONFIG=c:\kube\kube.conf. This command must be run every time you open a new cmd window.

Use kubectl version to verify that the client and server information is output correctly.

Setting global environment variables

In the Windows environment, you need to register the directory in the PATH environment variable so that it can be used from any location. And if you register the kube.conf file you received earlier in the global environment variable, you can use the command right away without additional settings.

  • PATH is a system variable that the operating system uses to find required executables from a command line or terminal window.
    • The value adds the kubectl execution location we created above (c:\kube).
  • KUBECONFIG is a system variable for the location of the kubernetes configuration file required when executing the kubectl command.
    • The value is set to the location including the kube.conf file name (c:\kube\kube.conf).


To set it up, follow the instructions below depending on your operating system version.

Windows 10 and Windows 8

  1. Search for and select System (Control Panel) in [Search].
  2. Click the Advanced System Settings link.
  3. Click Environment Variables. In the System Variables section, locate and select the PATH environment variable. Click Edit. If the PATH environment variable does not exist, click New.
  4. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Click OK to close all remaining windows.
  5. Reopen the Command Prompt window and run the kubectl code.

Windows 7

  1. Right-click the Computer icon on your desktop.
  2. Select Properties from the context menu.
  3. Click the Advanced System Settings link.
  4. Click Environment Variables. In the System Variables section, locate and select the PATH environment variable. Click Edit. If the PATH environment variable does not exist, click New.
  5. In the Edit System Variable (or New System Variable) window, specify a value for the PATH environment variable. Click OK. Click OK to close all remaining windows.
  6. Reopen the Command Prompt window and run the kubectl code.

Windows XP

  1. Select Start, Control Panel. Double-click System, and then select the Advanced tab.
  2. Click Environment Variables. In the System Variables section, locate and select the PATH environment variable. Click Edit. If the PATH environment variable does not exist, click New.
  3. In the Edit System Variable (or New System Variable) window, specify a value for the PATH environment variable. Click OK. Click OK to close all remaining windows.


Uploading sources to the source repository

Gitea integrated login settings

From the side menu, click DevOps > Source Repositories.

On the screen below, you will first register as a member of the source repository. From now on, you will be able to access it without logging in separately.

Be careful not to lose your password as it will be used when using storage such as Push.

Once you have completed registration, click the OpenId Connect image to log in.

Usage is similar to Github, and you can create files directly from the web screen or check them out locally and work on them.


View build log

The pushed source code is deployed to the Kubernetes cluster via Pipeline (Jenkins).

The build/deployment process is performed by the CI/CD Manager, but errors may occur during the build/deployment process due to the source code.

In this case, you can check the execution log of the pipeline using the method below.


Z CP Console > DevOps > Clicking Build and Deploy will take you to Jenkins, where you will see the folders in the namespaces you have permission to view.

Click the namespace folder you want to check > Build Job.


You can check the build execution history in Build History on the left side of the screen, and you can view the build log by clicking the icon to the left of the build number.


View Pod Logs

Once the build/deployment is complete, the application will be deployed to kubernetes.

In the process of testing/servicing a deployed application, it becomes necessary to check logs and deployed settings.


Deployed applications are managed as internal Kubernetes resources called Pods.

First, check the name of the Pod for which you want to check the log using the kubectl get pod -n (namespace name) command.

kubectl logs (Pod 이름) -n (Check the log by running the command (namespace name).

To specify the number of lines to initially output, use the --tail=(number of lines) option.

If you want to check the logs that are continuously output, use the -f option.

For other options and detailed descriptions, see the kubectl --help command.

Online consultation

Contact us

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.