[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"/en/kb/manual/kubectlKbData":3},{"page":4,"pages":108,"recommendedPages":109,"category":41,"categoryTree":41,"total":115,"currentOrder":138,"activeManualCategoryId":41,"tag":-1},{"route":5,"uuid":8,"title":9,"excerpt":10,"content":11,"view_count":12,"published_at":13,"modified_at":13,"like":14,"category":17,"hero_image":34,"seo_metadata":35,"schema_org_metadata":39,"open_graph_metadata":42,"sections":43,"tags":103,"breadcrumbs":104,"images":107},{"language":6,"path":7},"en","/kb/manual/kubectl","dcc74387-0d06-c465-e56b-f66a99e90faa","Connecting to the cluster and using kubectl","Once the cluster is created, you can connect to it using kubectl, a command-line tool for managing Kubernetes. With kubectl, you can create and delete resources, view the cluster status, read application logs, and perform other operations.","\u003Cp>Once the cluster is created, you can connect to it using kubectl, a command-line tool for managing Kubernetes. With kubectl, you can create and delete resources, view the cluster status, read application logs, and perform other operations.\u003C/p>\n\u003Cp>If you’re not familiar with the basics of Kubernetes, start with the article “\u003Ca href=\"https://beget.com/en/kb/manual/what-is-kubernetes\">Kubernetes Basics\u003C/a>”.\u003C/p>\n\u003Ch2 id=\"installing-kubectl\">Installing kubectl\u003C/h2>\n\u003Ch3 id=\"linux-ubuntu-and-other-distributions\">Linux (Ubuntu and other distributions)\u003C/h3>\n\u003Cp>Installing kubectl on Ubuntu and other Linux distributions:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;shell&quot;}\">\u003Ccode>curl -LO \"https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl\"\nchmod +x kubectl\nsudo mv kubectl /usr/local/bin/\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch3 id=\"macos\">macOS\u003C/h3>\n\u003Cp>Via Homebrew (package manager):\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>brew install kubectl\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>Or manually (Apple Silicon):\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;shell&quot;}\">\u003Ccode>curl -LO \"https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/arm64/kubectl\"\nchmod +x kubectl\nsudo mv kubectl /usr/local/bin/\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch3 id=\"windows\">Windows\u003C/h3>\n\u003Cp>Install kubectl on Windows using winget (the package manager):\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>winget install Kubernetes.kubectl\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>Or manually: download the executable file from the \u003Ca href=\"https://kubernetes.io/releases/\" rel=\"nofollow\">releases page\u003C/a> and add its path to the \u003Ccode>PATH\u003C/code> environment variable.\u003C/p>\n\u003Ch3 id=\"verifying-the-installation\">Verifying the installation\u003C/h3>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>kubectl version --client\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>Expected output:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>Client Version: v1.xx.x\nKustomize Version: v5.x.x\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch2 id=\"obtaining-the-kubeconfig\">Obtaining the kubeconfig\u003C/h2>\n\u003Cp>A kubeconfig is a configuration file that contains authentication credentials and the API server address (Application Programming Interface) for your Kubernetes cloud cluster. Without it, kubectl will not be able to connect to the cluster.\u003C/p>\n\u003Cp>To download the kubeconfig:\u003C/p>\n\u003Col>\n\u003Cli>Go to the dashboard of the created cluster\u003C/li>\n\u003Cli>In the “Information” tab, click ‘Connect’\u003C/li>\n\u003Cli>In the window that opens, click “Download kubeconfig”\u003C/li>\n\u003Cli>Save the file to your local computer\u003C/li>\n\u003C/ol>\n\u003Ch2 id=\"first-connection\">First Connection\u003C/h2>\n\u003Cp>Run the following command to check the connection:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>kubectl --kubeconfig kubeconfig.yaml get nodes\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>If the connection was successful, you will see a list of nodes (server groups) in your K8s cluster:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>NAME                                    STATUS   ROLES    AGE   VERSION\ndc5bca-client-c31fdf-xkd6w-jqpnc       Ready    &lt;none&gt;   2m    v1.xx.x\ndc5bca-client-c31fdf-xkd6w-rq847       Ready    &lt;none&gt;   70s   v1.xx.x\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>The \u003Ccode>Ready\u003C/code> status means that the nodes are operational and ready to handle traffic. If a node has a “NotReady” status, it most likely lacks sufficient resources. In this case, please contact technical support for troubleshooting.\u003C/p>\n\u003Ch2 id=\"configuring-kubectl-for-convenience\">Configuring kubectl for Convenience\u003C/h2>\n\u003Ch3 id=\"the-kubeconfig-environment-variable\">The kubeconfig Environment Variable\u003C/h3>\n\u003Cp>To avoid having to specify \u003Ccode>--kubeconfig\u003C/code> in every command, set the path to the file via an environment variable:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>export KUBECONFIG=/path/to/kubeconfig.yaml\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>After that, kubectl will use the specified file automatically:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>kubectl get nodes\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>To preserve this setting across sessions, add the line export \u003Ccode>KUBECONFIG=...\u003C/code> to the \u003Ccode>~/.bashrc\u003C/code> (Linux) or \u003Ccode>~/.zshrc\u003C/code> (macOS) file.\u003C/p>\n\u003Ch3 id=\"moving-to-the-default-location\">Moving to the Default Location\u003C/h3>\n\u003Cp>An alternative method is to move the kubeconfig to the default kubectl directory:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>mkdir -p ~/.kube\ncp kubeconfig.yaml ~/.kube/config\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>kubectl automatically looks for the configuration in \u003Ccode>~/.kube/config\u003C/code> if the \u003Ccode>KUBECONFIG\u003C/code> variable is not set.\u003C/p>\n\u003Ch3 id=\"working-with-multiple-clusters\">Working with Multiple Clusters\u003C/h3>\n\u003Cp>If you have multiple clusters, you can combine their kubeconfig files and switch between them using contexts.\u003C/p>\n\u003Cp>View available contexts:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>kubectl config get-contexts\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>Switch to a different context:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>kubectl config use-context &lt;context-name&gt;\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>To combine multiple kubeconfig files:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>export KUBECONFIG=~/.kube/config:/path/to/second-kubeconfig.yaml\nkubectl config view --merge --flatten &gt; ~/.kube/merged-config\nmv ~/.kube/merged-config ~/.kube/config\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch2 id=\"basic-kubectl-commands\">Basic kubectl Commands\u003C/h2>\n\u003Cp>Below are the main kubectl commands for everyday work with the cluster.\u003C/p>\n\u003Ch3 id=\"viewing-resources\">Viewing Resources\u003C/h3>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode># List cluster nodes\nkubectl get nodes\n\n# List pods in all namespaces\nkubectl get pods --all-namespaces\n\n# List pods in a specific namespace\nkubectl get pods -n my-namespace\n\n# Detailed information about a pod\nkubectl describe pod &lt;name-pod&gt;\n\n# List services\nkubectl get svc\n\n# List all resources in a namespace\nkubectl get all -n my-namespace\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch3 id=\"creating-and-applying-resources\">Creating and Applying Resources\u003C/h3>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode># Apply a manifest from a file\nkubectl apply -f manifest.yaml\n\n# Apply all manifests from a directory\nkubectl apply -f ./manifests/\n\n# Create a namespace\nkubectl create namespace my-app\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch3 id=\"logs-and-debugging\">Logs and Debugging\u003C/h3>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode># Pod logs\nkubectl logs &lt;name-pod&gt;\n\n# Real-time logs\nkubectl logs -f &lt;name-pod&gt;\n\n# Logs for a specific container in a pod\nkubectl logs &lt;name-pod&gt; -c &lt;name-container&gt;\n\n# Run a command inside a pod\nkubectl exec -it &lt;name-pod&gt; -- /bin/sh\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch3 id=\"deleting-resources\">Deleting resources\u003C/h3>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode># Delete a resource using a manifest\nkubectl delete -f manifest.yaml\n\n# Delete a pod\nkubectl delete pod &lt;name-pod&gt;\n\n# Delete all pods in a namespace\nkubectl delete pods --all -n my-namespace\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch3 id=\"useful-flags\">Useful flags\u003C/h3>\n\u003Cul>\n\u003Cli>\u003Ccode>-o wide\u003C/code> – extended output with additional columns\u003C/li>\n\u003Cli>\u003Ccode>-o yaml\u003C/code> – output in YAML format (a language for storing information)\u003C/li>\n\u003Cli>\u003Ccode>-o json\u003C/code> – output in JSON format (a text-based data exchange format)\u003C/li>\n\u003Cli>\u003Ccode>-w\u003C/code> / \u003Ccode>--watch\u003C/code> – monitor changes in real time\u003C/li>\n\u003Cli>\u003Ccode>-n &lt;namespace&gt;\u003C/code> – specify a namespace (default is default)\u003C/li>\n\u003C/ul>\n\u003Cp>Example:\u003C/p>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>kubectl get pods -o wide -w\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch2 id=\"command-autocompletion\">Command autocompletion\u003C/h2>\n\u003Cp>kubectl supports autocompletion for bash and zsh.\u003C/p>\n\u003Ch3 id=\"bash\">bash\u003C/h3>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>echo 'source &lt;(kubectl completion bash)' &gt;&gt; ~/.bashrc\nsource ~/.bashrc\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Ch3 id=\"zsh\">zsh\u003C/h3>\n\u003Cdiv class=\"wp-block-beget-code code-block\">\n\u003Cpre data-options=\"{&quot;mode&quot;:&quot;&quot;}\">\u003Ccode>echo 'source &lt;(kubectl completion zsh)' &gt;&gt; ~/.zshrc\nsource ~/.zshrc\u003C/code>\u003C/pre>\n\u003C/div>\n\u003Cp>After configuration, press “Tab” to autocomplete commands, resource names, and flags.\u003C/p>\n\u003Cp>All articles in this section\u003C/p>\n\u003Col>\n\u003Cli>\u003Ca href=\"https://beget.com/en/kb/manual/managed-kubernetes\">Kubernetes (K8s)\u003C/a> – An Overview of the Managed Kubernetes Service\u003C/li>\n\u003Cli>\u003Ca href=\"https://beget.com/en/kb/manual/what-is-kubernetes\">Kubernetes Basics\u003C/a> – Key Concepts: Cluster, Nodes, Pods, Services\u003C/li>\n\u003Cli>\u003Ca href=\"https://beget.com/en/kb/manual/creating-and-configuring-cluster-kubernetes\">Creating and Configuring a Cluster\u003C/a> – Master Node Configuration, Networking, and Worker Groups\u003C/li>\n\u003Cli>\u003Cstrong>Connecting to the Cluster and Working with kubectl\u003C/strong> – You are here\u003C/li>\n\u003Cli>\u003Ca href=\"https://beget.com/en/kb/manual/cluster-management-kubernetes\">Cluster management\u003C/a> – adding nodes, changing configuration, updating, and deleting\u003C/li>\n\u003Cli>\u003Ca href=\"https://beget.com/en/kb/manual/network-and-load-balancer-kubernetes\">Networking and load balancers\u003C/a> – network model, external and internal load balancers\u003C/li>\n\u003Cli>\u003Ca href=\"https://beget.com/en/kb/manual/limits-quotas-restrictions-kubernetes\">Limits, quotas, and constraints\u003C/a> – platform constraints, what can and cannot be changed\u003C/li>\n\u003C/ol>\n\u003Cp>If you have any questions, please submit a ticket via the account dashboard (under “\u003Ca href=\"https://cp.beget.com/support?utm_source=kb&amp;utm_medium=article&amp;utm_campaign=kubernetes_kubectl&amp;utm_content=cp_support\">Help and Support\u003C/a>”). And if you’d like to discuss this article or our products, we’d love to see you in our Telegram \u003Ca href=\"https://t.me/beget_chat\">community\u003C/a>.\u003C/p>\n",50,"2026-11-11T14:50:32.000Z",{"count":15,"liked":16},1,false,{"route":18,"title":20,"tags":21,"breadcrumbs":27,"uuid":28,"parent_uuid":29,"default_page_path":26,"seo_metadata":30},{"language":6,"path":19},"/kb/manual","Control Panel User's Manual",[22],{"id":23,"title":24,"seo_metadata":25},"vps","VPS",{"title":26,"description":26,"header":26,"keywords":26},"",[],"5afe272b-ca8e-731e-0871-c5b169760081","80213437-0399-4b4f-2333-426bb5050534",{"title":31,"description":32,"header":31,"keywords":33},"Beget Hosting Panel Guide","Руководство по панели управления Beget. Инструкции по работе с аккаунтом, файловыми менеджерами, почтой, CMS и др.","hosting panel instructions, hosting beget",{"src":26,"text":26},{"title":36,"description":37,"keywords":38},"kubectl: Installation and Configuration Guide","Guide to Installing, Configuring, and Connecting the kubectl Console Utility in Beget Cloud ✔ Step-by-Step Instructions","Beget User Guide for Using the kubectl Service: A Guide and Documentation for the Kubernetes API Client",{"faq":40,"how_to":41,"product":41},[],null,{},[44,47,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,101],{"level":15,"name":45,"anchor":46},"Installing kubectl","installing-kubectl",{"level":48,"name":49,"anchor":50},2,"Linux (Ubuntu and other distributions)","linux-ubuntu-and-other-distributions",{"level":48,"name":52,"anchor":53},"macOS","macos",{"level":48,"name":55,"anchor":56},"Windows","windows",{"level":48,"name":58,"anchor":59},"Verifying the installation","verifying-the-installation",{"level":15,"name":61,"anchor":62},"Obtaining the kubeconfig","obtaining-the-kubeconfig",{"level":15,"name":64,"anchor":65},"First Connection","first-connection",{"level":15,"name":67,"anchor":68},"Configuring kubectl for Convenience","configuring-kubectl-for-convenience",{"level":48,"name":70,"anchor":71},"The kubeconfig Environment Variable","the-kubeconfig-environment-variable",{"level":48,"name":73,"anchor":74},"Moving to the Default Location","moving-to-the-default-location",{"level":48,"name":76,"anchor":77},"Working with Multiple Clusters","working-with-multiple-clusters",{"level":15,"name":79,"anchor":80},"Basic kubectl Commands","basic-kubectl-commands",{"level":48,"name":82,"anchor":83},"Viewing Resources","viewing-resources",{"level":48,"name":85,"anchor":86},"Creating and Applying Resources","creating-and-applying-resources",{"level":48,"name":88,"anchor":89},"Logs and Debugging","logs-and-debugging",{"level":48,"name":91,"anchor":92},"Deleting resources","deleting-resources",{"level":48,"name":94,"anchor":95},"Useful flags","useful-flags",{"level":15,"name":97,"anchor":98},"Command autocompletion","command-autocompletion",{"level":48,"name":100,"anchor":100},"bash",{"level":48,"name":102,"anchor":102},"zsh",[],[105],{"route":106,"title":20},{"language":6,"path":19},[],[],[110,120,129],{"route":111,"uuid":113,"title":114,"excerpt":26,"content":26,"view_count":115,"published_at":26,"modified_at":26,"like":41,"category":41,"hero_image":41,"seo_metadata":41,"schema_org_metadata":41,"open_graph_metadata":41,"sections":116,"tags":117,"breadcrumbs":118,"images":119},{"language":6,"path":112},"/kb/manual/dns","c4261afe-ce3a-914d-df27-aa76c93446cf","DNS",0,[],[],[],[],{"route":121,"uuid":123,"title":124,"excerpt":26,"content":26,"view_count":115,"published_at":26,"modified_at":26,"like":41,"category":41,"hero_image":41,"seo_metadata":41,"schema_org_metadata":41,"open_graph_metadata":41,"sections":125,"tags":126,"breadcrumbs":127,"images":128},{"language":6,"path":122},"/kb/manual/domains","b231d5f2-9688-cb24-0b37-9ece8b8940c9","Domains",[],[],[],[],{"route":130,"uuid":132,"title":133,"excerpt":26,"content":26,"view_count":115,"published_at":26,"modified_at":26,"like":41,"category":41,"hero_image":41,"seo_metadata":41,"schema_org_metadata":41,"open_graph_metadata":41,"sections":134,"tags":135,"breadcrumbs":136,"images":137},{"language":6,"path":131},"/kb/manual/cms","0458f05b-7e52-1312-fae2-0aa2e404b4b1","CMS",[],[],[],[],"popularity-desc"]