Cài đặt Và Cấu Hình Kubectl | Kubernetes

Tiếng Việt (Vietnamese)English বাংলা (Bengali) 中文 (Chinese) Français (French) Deutsch (German) हिन्दी (Hindi) Bahasa Indonesia (Indonesian) Italiano (Italian) 日本語 (Japanese) 한국어 (Korean) Polski (Polish) Português (Portuguese) Русский (Russian) Español (Spanish) Українська (Ukrainian)
  • Tài liệu
    • Tài liệu
      • Các phiên bản được hỗ trợ của tài liệu Kubernetes
    • Bắt đầu với Kubernetes
      • Learning environment (EN)
      • Môi trường Production
        • Container Runtimes (EN)
        • Cài đặt Kubernetes với các công cụ triển khai
          • Khởi tạo cụm với kubeadm
            • Cài đặt kubeadm
            • Troubleshooting kubeadm (EN)
            • Creating a cluster with kubeadm (EN)
            • Customizing components with the kubeadm API (EN)
            • Các tùy chọn cho kiến trúc có tính Sẵn sàng cao
            • Tạo các cụm có tính Sẵn sàng cao với kubeadm
            • Thiết lập một cụm etcd có tính Sẵn sàng cao (High Availability) với kubeadm
            • Configuring each kubelet in your cluster using kubeadm (EN)
            • Dual-stack support with kubeadm (EN)
        • Turnkey Cloud Solutions (EN)
      • Một số cách thức cài đặt tốt
        • Considerations for large clusters (EN)
        • Running in multiple zones (EN)
        • Validate node setup (EN)
        • Enforcing Pod Security Standards (EN)
        • PKI certificates and requirements (EN)
    • Các khái niệm
      • Tổng quan
        • Kubernetes Components (EN)
        • Kubernetes là gì
        • Objects In Kubernetes (EN)
          • Kubernetes Object Management (EN)
          • Object Names and IDs (EN)
          • Labels and Selectors (EN)
          • Namespaces (EN)
          • Annotations (EN)
          • Field Selectors (EN)
          • Finalizers (EN)
          • Owners and Dependents (EN)
          • Recommended Labels (EN)
        • The Kubernetes API (EN)
      • Kiến Trúc Cluster
        • Nodes (EN)
        • Communication between Nodes and the Control Plane (EN)
        • Controllers (EN)
        • Leases
        • Các khái niệm nền tảng của Cloud Controller Manager
        • About cgroup v2 (EN)
        • Kubernetes Self-Healing (EN)
        • Garbage Collection (EN)
        • Proxy Đa Phiên Bản (Mixed Version Proxy)
      • Containers
        • Images (EN)
        • Các biến môi trường của Container
        • Container Environment (EN)
        • Container Lifecycle Hooks
        • Runtime Class (EN)
        • Container Runtime Interface (CRI) (EN)
      • Workloads (EN)
        • Pods (EN)
          • Pod Lifecycle (EN)
          • Init Containers (EN)
          • Sidecar Containers (EN)
          • Ephemeral Containers (EN)
          • Disruptions (EN)
          • Pod Hostname (EN)
          • Pod Quality of Service Classes (EN)
          • User Namespaces (EN)
          • Downward API (EN)
        • Workload Management (EN)
          • Deployments (EN)
          • ReplicaSet (EN)
          • StatefulSets (EN)
          • DaemonSet (EN)
          • Jobs (EN)
          • Automatic Cleanup for Finished Jobs (EN)
          • CronJob (EN)
          • ReplicationController (EN)
        • Autoscaling Workloads (EN)
        • Managing Workloads (EN)
        • Vertical Pod Autoscaling (EN)
      • Services, Load Balancing, and Networking (EN)
        • Service (EN)
        • Ingress (EN)
        • Ingress Controllers (EN)
        • Gateway API (EN)
        • EndpointSlices (EN)
        • Network Policies (EN)
        • DNS for Services and Pods (EN)
        • IPv4/IPv6 dual-stack (EN)
        • Topology Aware Routing (EN)
        • Networking on Windows (EN)
        • Service ClusterIP allocation (EN)
        • Service Internal Traffic Policy (EN)
      • Storage (EN)
        • Volumes (EN)
        • Persistent Volumes (EN)
        • Projected Volumes (EN)
        • Ephemeral Volumes (EN)
        • Storage Classes (EN)
        • Volume Attributes Classes (EN)
        • Dynamic Volume Provisioning (EN)
        • Volume Snapshots (EN)
        • Volume Snapshot Classes (EN)
        • CSI Volume Cloning (EN)
        • Storage Capacity (EN)
        • Node-specific Volume Limits (EN)
        • Local ephemeral storage (EN)
        • Volume Health Monitoring (EN)
        • Windows Storage (EN)
      • Configuration (EN)
        • ConfigMaps (EN)
        • Secrets (EN)
        • Liveness, Readiness, and Startup Probes (EN)
        • Resource Management for Pods and Containers (EN)
        • Organizing Cluster Access Using kubeconfig Files (EN)
        • Resource Management for Windows nodes (EN)
      • Security (EN)
        • Cloud Native Security (EN)
        • Pod Security Standards (EN)
        • Pod Security Admission (EN)
        • Service Accounts (EN)
        • Pod Security Policies (EN)
        • Security For Linux Nodes (EN)
        • Security For Windows Nodes (EN)
        • Controlling Access to the Kubernetes API (EN)
        • Role Based Access Control Good Practices (EN)
        • Good practices for Kubernetes Secrets (EN)
        • Multi-tenancy (EN)
        • Hardening Guide - Authentication Mechanisms (EN)
        • Hardening Guide - Scheduler Configuration (EN)
        • Kubernetes API Server Bypass Risks (EN)
        • Linux kernel security constraints for Pods and containers (EN)
        • Security Checklist (EN)
        • Application Security Checklist (EN)
      • Policies (EN)
        • Limit Ranges (EN)
        • Resource Quotas (EN)
        • Process ID Limits And Reservations (EN)
        • Node Resource Managers (EN)
      • Scheduling, Preemption and Eviction (EN)
        • Kubernetes Scheduler (EN)
        • Assigning Pods to Nodes (EN)
        • Pod Overhead (EN)
        • Pod Scheduling Readiness (EN)
        • Pod Topology Spread Constraints (EN)
        • Taints and Tolerations (EN)
        • Scheduling Framework (EN)
        • Dynamic Resource Allocation (EN)
        • Scheduler Performance Tuning (EN)
        • Resource Bin Packing (EN)
        • Pod Priority and Preemption (EN)
        • Node-pressure Eviction (EN)
        • API-initiated Eviction (EN)
      • Cluster Administration (EN)
        • Node Shutdowns (EN)
        • Swap memory management (EN)
        • Node Autoscaling (EN)
        • Certificates (EN)
        • Cluster Networking (EN)
        • Observability (EN)
        • Admission Webhook Good Practices (EN)
        • Good practices for Dynamic Resource Allocation as a Cluster Admin (EN)
        • Logging Architecture (EN)
        • Compatibility Version For Kubernetes Control Plane Components (EN)
        • Metrics For Kubernetes System Components (EN)
        • Metrics for Kubernetes Object States (EN)
        • System Logs (EN)
        • Traces For Kubernetes System Components (EN)
        • Proxies in Kubernetes (EN)
        • API Priority and Fairness (EN)
        • Installing Addons (EN)
        • Coordinated Leader Election (EN)
      • Windows in Kubernetes (EN)
        • Windows containers in Kubernetes (EN)
        • Guide for Running Windows Containers in Kubernetes (EN)
      • Extending Kubernetes (EN)
        • Compute, Storage, and Networking Extensions (EN)
          • Network Plugins (EN)
          • Device Plugins (EN)
        • Extending the Kubernetes API (EN)
          • Custom Resources (EN)
          • Kubernetes API Aggregation Layer (EN)
        • Operator pattern (EN)
    • Tasks
      • Cài đặt các công cụ
        • Cài đặt và cấu hình kubectl
        • Install and Set Up kubectl on Linux (EN)
        • Install and Set Up kubectl on macOS (EN)
        • Install and Set Up kubectl on Windows (EN)
        • Cài đặt Minikube
      • Administer a Cluster (EN)
        • Administration with kubeadm (EN)
          • Adding Linux worker nodes (EN)
          • Adding Windows worker nodes (EN)
          • Upgrading kubeadm clusters (EN)
          • Upgrading Linux nodes (EN)
          • Upgrading Windows nodes (EN)
          • Configuring a cgroup driver (EN)
          • Certificate Management with kubeadm (EN)
          • Reconfiguring a kubeadm cluster (EN)
          • Changing The Kubernetes Package Repository (EN)
        • Overprovision Node Capacity For A Cluster (EN)
        • Migrating from dockershim (EN)
          • Changing the Container Runtime on a Node from Docker Engine to containerd (EN)
          • Find Out What Container Runtime is Used on a Node (EN)
          • Check whether dockershim removal affects you (EN)
          • Migrating telemetry and security agents from dockershim (EN)
        • Generate Certificates Manually (EN)
        • Manage Memory, CPU, and API Resources (EN)
          • Configure Default Memory Requests and Limits for a Namespace (EN)
          • Configure Default CPU Requests and Limits for a Namespace (EN)
          • Configure Minimum and Maximum Memory Constraints for a Namespace (EN)
          • Configure Minimum and Maximum CPU Constraints for a Namespace (EN)
          • Configure Memory and CPU Quotas for a Namespace (EN)
          • Configure a Pod Quota for a Namespace (EN)
        • Install a Network Policy Provider (EN)
          • Use Antrea for NetworkPolicy (EN)
          • Use Calico for NetworkPolicy (EN)
          • Use Cilium for NetworkPolicy (EN)
          • Use Kube-router for NetworkPolicy (EN)
          • Romana for NetworkPolicy (EN)
          • Weave Net for NetworkPolicy (EN)
        • Access Clusters Using the Kubernetes API (EN)
        • Enable Or Disable Feature Gates (EN)
        • Advertise Extended Resources for a Node (EN)
        • Autoscale the DNS Service in a Cluster (EN)
        • Change the Access Mode of a PersistentVolume to ReadWriteOncePod (EN)
        • Change the default StorageClass (EN)
        • Switching from Polling to CRI Event-based Updates to Container Status (EN)
        • Change the Reclaim Policy of a PersistentVolume (EN)
        • Cloud Controller Manager Administration (EN)
        • Configure a kubelet image credential provider (EN)
        • Configure Quotas for API Objects (EN)
        • Control CPU Management Policies on the Node (EN)
        • Control Topology Management Policies on a node (EN)
        • Customizing DNS Service (EN)
        • Debugging DNS Resolution (EN)
        • Declare Network Policy (EN)
        • Developing Cloud Controller Manager (EN)
        • Enable Or Disable A Kubernetes API (EN)
        • Encrypting Confidential Data at Rest (EN)
        • Decrypt Confidential Data that is Already Encrypted at Rest (EN)
        • Guaranteed Scheduling For Critical Add-On Pods (EN)
        • IP Masquerade Agent User Guide (EN)
        • Limit Storage Consumption (EN)
        • Migrate Replicated Control Plane To Use Cloud Controller Manager (EN)
        • Operating etcd clusters for Kubernetes (EN)
        • Reserve Compute Resources for System Daemons (EN)
        • Running Kubernetes Node Components as a Non-root User (EN)
        • Safely Drain a Node (EN)
        • Securing a Cluster (EN)
        • Set Kubelet Parameters Via A Configuration File (EN)
        • Share a Cluster with Namespaces (EN)
        • Upgrade A Cluster (EN)
        • Use Cascading Deletion in a Cluster (EN)
        • Using a KMS provider for data encryption (EN)
        • Using CoreDNS for Service Discovery (EN)
        • Using NodeLocal DNSCache in Kubernetes Clusters (EN)
        • Using sysctls in a Kubernetes Cluster (EN)
        • Utilizing the NUMA-aware Memory Manager (EN)
        • Verify Signed Kubernetes Artifacts (EN)
      • Cấu hình Pods và Containers
        • Cấp phát tài nguyên bộ nhớ cho Containers và Pods
        • Assign CPU Resources to Containers and Pods (EN)
        • Assign Devices to Pods and Containers (EN)
          • Set Up DRA in a Cluster (EN)
          • Allocate Devices to Workloads with DRA (EN)
        • Assign Pod-level CPU and memory resources (EN)
        • Configure GMSA for Windows Pods and containers (EN)
        • Resize CPU and Memory Resources assigned to Containers (EN)
        • Configure RunAsUserName for Windows pods and containers (EN)
        • Create a Windows HostProcess Pod (EN)
        • Configure Quality of Service for Pods (EN)
        • Assign Extended Resources to a Container (EN)
        • Configure a Pod to Use a Volume for Storage (EN)
        • Configure a Pod to Use a PersistentVolume for Storage (EN)
        • Configure a Pod to Use a Projected Volume for Storage (EN)
        • Configure a Security Context for a Pod or Container (EN)
        • Configure Service Accounts for Pods (EN)
        • Pull an Image from a Private Registry (EN)
        • Configure Liveness, Readiness and Startup Probes (EN)
        • Assign Pods to Nodes (EN)
        • Assign Pods to Nodes using Node Affinity (EN)
        • Configure Pod Initialization (EN)
        • Attach Handlers to Container Lifecycle Events (EN)
        • Configure a Pod to Use a ConfigMap (EN)
        • Share Process Namespace between Containers in a Pod (EN)
        • Use a User Namespace With a Pod (EN)
        • Use an Image Volume With a Pod (EN)
        • Create static Pods (EN)
        • Translate a Docker Compose File to Kubernetes Resources (EN)
        • Enforce Pod Security Standards by Configuring the Built-in Admission Controller (EN)
        • Enforce Pod Security Standards with Namespace Labels (EN)
        • Migrate from PodSecurityPolicy to the Built-In PodSecurity Admission Controller (EN)
      • Monitoring, Logging, and Debugging (EN)
        • Logging in Kubernetes (EN)
        • Monitoring in Kubernetes (EN)
        • Troubleshooting Applications (EN)
          • Debug Pods (EN)
          • Debug Services (EN)
          • Debug a StatefulSet (EN)
          • Determine the Reason for Pod Failure (EN)
          • Debug Init Containers (EN)
          • Debug Running Pods (EN)
          • Get a Shell to a Running Container (EN)
        • Troubleshooting Clusters (EN)
          • Troubleshooting kubectl (EN)
          • Resource metrics pipeline (EN)
          • Tools for Monitoring Resources (EN)
          • Monitor Node Health (EN)
          • Debugging Kubernetes nodes with crictl (EN)
          • Auditing (EN)
          • Debugging Kubernetes Nodes With Kubectl (EN)
          • Developing and debugging services locally using telepresence (EN)
          • Windows debugging tips (EN)
      • Manage Kubernetes Objects (EN)
        • Declarative Management of Kubernetes Objects Using Configuration Files (EN)
        • Declarative Management of Kubernetes Objects Using Kustomize (EN)
        • Managing Kubernetes Objects Using Imperative Commands (EN)
        • Imperative Management of Kubernetes Objects Using Configuration Files (EN)
        • Update API Objects in Place Using kubectl patch (EN)
        • Migrate Kubernetes Objects Using Storage Version Migration (EN)
      • Managing Secrets (EN)
        • Managing Secrets using kubectl (EN)
        • Managing Secrets using Configuration File (EN)
        • Managing Secrets using Kustomize (EN)
      • Inject Data Into Applications (EN)
        • Define a Command and Arguments for a Container (EN)
        • Define Dependent Environment Variables (EN)
        • Define Environment Variables for a Container (EN)
        • Define Environment Variable Values Using An Init Container (EN)
        • Expose Pod Information to Containers Through Environment Variables (EN)
        • Expose Pod Information to Containers Through Files (EN)
        • Distribute Credentials Securely Using Secrets (EN)
      • Run Applications (EN)
        • Run a Stateless Application Using a Deployment (EN)
        • Run a Single-Instance Stateful Application (EN)
        • Run a Replicated Stateful Application (EN)
        • Scale a StatefulSet (EN)
        • Delete a StatefulSet (EN)
        • Force Delete StatefulSet Pods (EN)
        • Horizontal Pod Autoscaling (EN)
        • HorizontalPodAutoscaler Walkthrough (EN)
        • Specifying a Disruption Budget for your Application (EN)
        • Accessing the Kubernetes API from a Pod (EN)
      • Run Jobs (EN)
        • Running Automated Tasks with a CronJob (EN)
        • Coarse Parallel Processing Using a Work Queue (EN)
        • Fine Parallel Processing Using a Work Queue (EN)
        • Indexed Job for Parallel Processing with Static Work Assignment (EN)
        • Job with Pod-to-Pod Communication (EN)
        • Parallel Processing using Expansions (EN)
        • Handling retriable and non-retriable pod failures with Pod failure policy (EN)
      • Access Applications in a Cluster (EN)
        • Deploy and Access the Kubernetes Dashboard (EN)
        • Accessing Clusters (EN)
        • Configure Access to Multiple Clusters (EN)
        • Use Port Forwarding to Access Applications in a Cluster (EN)
        • Use a Service to Access an Application in a Cluster (EN)
        • Connect a Frontend to a Backend Using Services (EN)
        • Create an External Load Balancer (EN)
        • List All Container Images Running in a Cluster (EN)
        • Communicate Between Containers in the Same Pod Using a Shared Volume (EN)
        • Configure DNS for a Cluster (EN)
        • Access Services Running on Clusters (EN)
      • Extend Kubernetes (EN)
        • Configure the Aggregation Layer (EN)
        • Use Custom Resources (EN)
          • Extend the Kubernetes API with CustomResourceDefinitions (EN)
          • Versions in CustomResourceDefinitions (EN)
        • Set up an Extension API Server (EN)
        • Configure Multiple Schedulers (EN)
        • Use an HTTP Proxy to Access the Kubernetes API (EN)
        • Use a SOCKS5 Proxy to Access the Kubernetes API (EN)
        • Set up Konnectivity service (EN)
      • TLS (EN)
        • Issue a Certificate for a Kubernetes API Client Using A CertificateSigningRequest (EN)
        • Configure Certificate Rotation for the Kubelet (EN)
        • Manage TLS Certificates in a Cluster (EN)
        • Manual Rotation of CA Certificates (EN)
      • Manage Cluster Daemons (EN)
        • Building a Basic DaemonSet (EN)
        • Perform a Rolling Update on a DaemonSet (EN)
        • Perform a Rollback on a DaemonSet (EN)
        • Running Pods on Only Some Nodes (EN)
      • Networking (EN)
        • Adding entries to Pod /etc/hosts with HostAliases (EN)
        • Extend Service IP Ranges (EN)
        • Kubernetes Default ServiceCIDR Reconfiguration (EN)
        • Validate IPv4/IPv6 dual-stack (EN)
      • Extend kubectl with plugins (EN)
      • Manage HugePages (EN)
      • Schedule GPUs (EN)
    • Tutorials
      • Hello Minikube (EN)
      • Học kiến thức cơ bản về Kubernetes
        • Tạo một Cluster
          • Sử dụng Minikube để tạo một Cluster
          • Hướng dẫn tương tác - Tạo một Cluster
        • Triển khai một ứng dụng
          • Sử dụng kubectl để triển khai ứng dụng
          • Hướng dẫn tương tác - Triển khai một ứng dụng
        • Khám phá ứng dụng
          • Khám Phá Pods Và Nodes
          • Hướng dẫn tương tác - Khám phá ứng dụng
        • Expose Your App Publicly (EN)
          • Using a Service to Expose Your App (EN)
        • Scale Your App (EN)
          • Running Multiple Instances of Your App (EN)
        • Update Your App (EN)
          • Performing a Rolling Update (EN)
      • Configuration (EN)
        • Updating Configuration via a ConfigMap (EN)
        • Configuring Redis using a ConfigMap (EN)
        • Adopting Sidecar Containers (EN)
      • Security (EN)
        • Apply Pod Security Standards at the Cluster Level (EN)
        • Apply Pod Security Standards at the Namespace Level (EN)
        • Restrict a Container's Access to Resources with AppArmor (EN)
        • Restrict a Container's Syscalls with seccomp (EN)
      • Stateless Applications (EN)
        • Exposing an External IP Address to Access an Application in a Cluster (EN)
        • Example: Deploying PHP Guestbook application with Redis (EN)
      • Stateful Applications (EN)
        • StatefulSet Basics (EN)
        • Example: Deploying WordPress and MySQL with Persistent Volumes (EN)
        • Example: Deploying Cassandra with a StatefulSet (EN)
        • Running ZooKeeper, A Distributed System Coordinator (EN)
      • Cluster Management (EN)
        • Running Kubelet in Standalone Mode (EN)
        • Configuring swap memory on Kubernetes nodes (EN)
        • Install Drivers and Allocate Devices with DRA (EN)
        • Namespaces Walkthrough (EN)
      • Services (EN)
        • Connecting Applications with Services (EN)
        • Using Source IP (EN)
        • Explore Termination Behavior for Pods And Their Endpoints (EN)
    • Tài liệu tham khảo
      • Thuật ngữ chuẩn hóa
      • API Overview (EN)
        • Declarative API Validation (EN)
        • Kubernetes API Concepts (EN)
        • Server-Side Apply (EN)
        • Client Libraries (EN)
        • Common Expression Language in Kubernetes (EN)
        • Kubernetes Deprecation Policy (EN)
        • Deprecated API Migration Guide (EN)
        • Kubernetes API health endpoints (EN)
      • API Access Control (EN)
        • Authenticating (EN)
        • Authenticating with Bootstrap Tokens (EN)
        • Authorization (EN)
        • Using RBAC Authorization (EN)
        • Using Node Authorization (EN)
        • Webhook Mode (EN)
        • Using ABAC Authorization (EN)
        • Admission Control (EN)
        • Dynamic Admission Control (EN)
        • Managing Service Accounts (EN)
        • Certificates and Certificate Signing Requests (EN)
        • Mapping PodSecurityPolicies to Pod Security Standards (EN)
        • Kubelet authentication/authorization (EN)
        • TLS bootstrapping (EN)
        • Mutating Admission Policy (EN)
        • Validating Admission Policy (EN)
      • Well-Known Labels, Annotations and Taints (EN)
        • Audit Annotations (EN)
      • Kubernetes API (EN)
        • Workload Resources (EN)
          • Pod (EN)
          • Binding (EN)
          • PodTemplate (EN)
          • ReplicationController (EN)
          • ReplicaSet (EN)
          • Deployment (EN)
          • StatefulSet (EN)
          • ControllerRevision (EN)
          • DaemonSet (EN)
          • Job (EN)
          • CronJob (EN)
          • HorizontalPodAutoscaler (EN)
          • HorizontalPodAutoscaler (EN)
          • PriorityClass (EN)
          • DeviceTaintRule v1alpha3 (EN)
          • ResourceClaim (EN)
          • ResourceClaimTemplate (EN)
          • ResourceSlice (EN)
        • Service Resources (EN)
          • Service (EN)
          • Endpoints (EN)
          • EndpointSlice (EN)
          • Ingress (EN)
          • IngressClass (EN)
        • Config and Storage Resources (EN)
          • ConfigMap (EN)
          • Secret (EN)
          • CSIDriver (EN)
          • CSINode (EN)
          • CSIStorageCapacity (EN)
          • PersistentVolumeClaim (EN)
          • PersistentVolume (EN)
          • StorageClass (EN)
          • StorageVersionMigration v1alpha1 (EN)
          • Volume (EN)
          • VolumeAttachment (EN)
          • VolumeAttributesClass (EN)
        • Authentication Resources (EN)
          • ServiceAccount (EN)
          • TokenRequest (EN)
          • TokenReview (EN)
          • CertificateSigningRequest (EN)
          • ClusterTrustBundle v1beta1 (EN)
          • SelfSubjectReview (EN)
          • PodCertificateRequest v1alpha1 (EN)
        • Authorization Resources (EN)
          • LocalSubjectAccessReview (EN)
          • SelfSubjectAccessReview (EN)
          • SelfSubjectRulesReview (EN)
          • SubjectAccessReview (EN)
          • ClusterRole (EN)
          • ClusterRoleBinding (EN)
          • Role (EN)
          • RoleBinding (EN)
        • Policy Resources (EN)
          • FlowSchema (EN)
          • LimitRange (EN)
          • ResourceQuota (EN)
          • NetworkPolicy (EN)
          • PodDisruptionBudget (EN)
          • PriorityLevelConfiguration (EN)
          • ValidatingAdmissionPolicy (EN)
          • ValidatingAdmissionPolicyBinding (EN)
          • MutatingAdmissionPolicy v1beta1 (EN)
          • MutatingAdmissionPolicyBinding v1alpha1 (EN)
        • Extend Resources (EN)
          • CustomResourceDefinition (EN)
          • DeviceClass (EN)
          • MutatingWebhookConfiguration (EN)
          • ValidatingWebhookConfiguration (EN)
        • Cluster Resources (EN)
          • APIService (EN)
          • ComponentStatus (EN)
          • Event (EN)
          • IPAddress (EN)
          • Lease (EN)
          • LeaseCandidate v1beta1 (EN)
          • Namespace (EN)
          • Node (EN)
          • RuntimeClass (EN)
          • ServiceCIDR (EN)
        • Common Definitions (EN)
          • DeleteOptions (EN)
          • LabelSelector (EN)
          • ListMeta (EN)
          • LocalObjectReference (EN)
          • NodeSelectorRequirement (EN)
          • ObjectFieldSelector (EN)
          • ObjectMeta (EN)
          • ObjectReference (EN)
          • Patch (EN)
          • Quantity (EN)
          • ResourceFieldSelector (EN)
          • Status (EN)
          • TypedLocalObjectReference (EN)
        • Other Resources (EN)
          • MutatingAdmissionPolicyBindingList v1beta1 (EN)
        • Common Parameters (EN)
      • Instrumentation (EN)
        • Service Level Indicator Metrics (EN)
        • CRI Pod & Container Metrics (EN)
        • Node metrics data (EN)
        • Understand Pressure Stall Information (PSI) Metrics (EN)
        • Kubernetes z-pages (EN)
        • Kubernetes Metrics Reference (EN)
      • Kubernetes Issues and Security (EN)
        • Kubernetes Issue Tracker (EN)
        • Kubernetes Security and Disclosure Information (EN)
        • CVE feed (EN)
      • Node Reference Information (EN)
        • Kubelet Checkpoint API (EN)
        • Linux Kernel Version Requirements (EN)
        • Articles on dockershim Removal and on Using CRI-compatible Runtimes (EN)
        • Node Labels Populated By The Kubelet (EN)
        • Local Files And Paths Used By The Kubelet (EN)
        • Kubelet Configuration Directory Merging (EN)
        • Kubelet Device Manager API Versions (EN)
        • Kubelet Systemd Watchdog (EN)
        • Node Status (EN)
        • Seccomp and Kubernetes (EN)
        • Linux Node Swap Behaviors (EN)
      • Networking Reference (EN)
        • Protocols for Services (EN)
        • Ports and Protocols (EN)
        • Virtual IPs and Service Proxies (EN)
      • Setup tools (EN)
        • Kubeadm (EN)
          • kubeadm init (EN)
          • kubeadm join (EN)
          • kubeadm upgrade (EN)
          • kubeadm upgrade phases (EN)
          • kubeadm config (EN)
          • kubeadm reset (EN)
          • kubeadm token (EN)
          • kubeadm version (EN)
          • kubeadm alpha (EN)
          • kubeadm certs (EN)
          • kubeadm init phase (EN)
          • kubeadm join phase (EN)
          • kubeadm kubeconfig (EN)
          • kubeadm reset phase (EN)
          • Implementation details (EN)
      • Command line tool (kubectl) (EN)
        • Introduction to kubectl (EN)
        • kubectl Quick Reference (EN)
        • kubectl reference (EN)
          • kubectl (EN)
          • kubectl annotate (EN)
          • kubectl api-resources (EN)
          • kubectl api-versions (EN)
          • kubectl apply (EN)
            • kubectl apply edit-last-applied (EN)
            • kubectl apply set-last-applied (EN)
            • kubectl apply view-last-applied (EN)
          • kubectl attach (EN)
          • kubectl auth (EN)
            • kubectl auth can-i (EN)
            • kubectl auth reconcile (EN)
            • kubectl auth whoami (EN)
          • kubectl autoscale (EN)
          • kubectl certificate (EN)
            • kubectl certificate approve (EN)
            • kubectl certificate deny (EN)
          • kubectl cluster-info (EN)
            • kubectl cluster-info dump (EN)
          • kubectl completion (EN)
          • kubectl config (EN)
            • kubectl config current-context (EN)
            • kubectl config delete-cluster (EN)
            • kubectl config delete-context (EN)
            • kubectl config delete-user (EN)
            • kubectl config get-clusters (EN)
            • kubectl config get-contexts (EN)
            • kubectl config get-users (EN)
            • kubectl config rename-context (EN)
            • kubectl config set (EN)
            • kubectl config set-cluster (EN)
            • kubectl config set-context (EN)
            • kubectl config set-credentials (EN)
            • kubectl config unset (EN)
            • kubectl config use-context (EN)
            • kubectl config view (EN)
          • kubectl cordon (EN)
          • kubectl cp (EN)
          • kubectl create (EN)
            • kubectl create clusterrole (EN)
            • kubectl create clusterrolebinding (EN)
            • kubectl create configmap (EN)
            • kubectl create cronjob (EN)
            • kubectl create deployment (EN)
            • kubectl create ingress (EN)
            • kubectl create job (EN)
            • kubectl create namespace (EN)
            • kubectl create poddisruptionbudget (EN)
            • kubectl create priorityclass (EN)
            • kubectl create quota (EN)
            • kubectl create role (EN)
            • kubectl create rolebinding (EN)
            • kubectl create secret (EN)
            • kubectl create secret docker-registry (EN)
            • kubectl create secret generic (EN)
            • kubectl create secret tls (EN)
            • kubectl create service (EN)
            • kubectl create service clusterip (EN)
            • kubectl create service externalname (EN)
            • kubectl create service loadbalancer (EN)
            • kubectl create service nodeport (EN)
            • kubectl create serviceaccount (EN)
            • kubectl create token (EN)
          • kubectl debug (EN)
          • kubectl delete (EN)
          • kubectl describe (EN)
          • kubectl diff (EN)
          • kubectl drain (EN)
          • kubectl edit (EN)
          • kubectl events (EN)
          • kubectl exec (EN)
          • kubectl explain (EN)
          • kubectl expose (EN)
          • kubectl get (EN)
          • kubectl kustomize (EN)
          • kubectl label (EN)
          • kubectl logs (EN)
          • kubectl options (EN)
          • kubectl patch (EN)
          • kubectl plugin (EN)
            • kubectl plugin list (EN)
          • kubectl port-forward (EN)
          • kubectl proxy (EN)
          • kubectl replace (EN)
          • kubectl rollout (EN)
            • kubectl rollout history (EN)
            • kubectl rollout pause (EN)
            • kubectl rollout restart (EN)
            • kubectl rollout resume (EN)
            • kubectl rollout status (EN)
            • kubectl rollout undo (EN)
          • kubectl run (EN)
          • kubectl scale (EN)
          • kubectl set (EN)
            • kubectl set env (EN)
            • kubectl set image (EN)
            • kubectl set resources (EN)
            • kubectl set selector (EN)
            • kubectl set serviceaccount (EN)
            • kubectl set subject (EN)
          • kubectl taint (EN)
          • kubectl top (EN)
            • kubectl top node (EN)
            • kubectl top pod (EN)
          • kubectl uncordon (EN)
          • kubectl version (EN)
          • kubectl wait (EN)
        • kubectl Commands (EN)
        • kubectl (EN)
        • JSONPath Support (EN)
        • kubectl for Docker Users (EN)
        • kubectl Usage Conventions (EN)
        • Kubectl user preferences (kuberc) (EN)
      • Component tools (EN)
        • Feature Gates (EN)
        • Feature Gates (removed) (EN)
        • kube-apiserver (EN)
        • kube-controller-manager (EN)
        • kube-proxy (EN)
        • kube-scheduler (EN)
        • kubelet (EN)
      • Debug cluster (EN)
        • Flow control (EN)
      • Configuration APIs (EN)
        • Client Authentication (v1) (EN)
        • Client Authentication (v1beta1) (EN)
        • Event Rate Limit Configuration (v1alpha1) (EN)
        • Image Policy API (v1alpha1) (EN)
        • kube-apiserver Admission (v1) (EN)
        • kube-apiserver Audit Configuration (v1) (EN)
        • kube-apiserver Configuration (v1) (EN)
        • kube-apiserver Configuration (v1alpha1) (EN)
        • kube-apiserver Configuration (v1beta1) (EN)
        • kube-controller-manager Configuration (v1alpha1) (EN)
        • kube-proxy Configuration (v1alpha1) (EN)
        • kube-scheduler Configuration (v1) (EN)
        • kubeadm Configuration (v1beta3) (EN)
        • kubeadm Configuration (v1beta4) (EN)
        • kubeconfig (v1) (EN)
        • Kubelet Configuration (v1) (EN)
        • Kubelet Configuration (v1alpha1) (EN)
        • Kubelet Configuration (v1beta1) (EN)
        • Kubelet CredentialProvider (v1) (EN)
        • kuberc (v1alpha1) (EN)
        • kuberc (v1beta1) (EN)
        • WebhookAdmission Configuration (v1) (EN)
      • External APIs (EN)
        • Kubernetes Custom Metrics (v1beta2) (EN)
        • Kubernetes External Metrics (v1beta1) (EN)
        • Kubernetes Metrics (v1beta1) (EN)
      • Scheduling (EN)
        • Scheduler Configuration (EN)
        • Scheduling Policies (EN)
      • Other Tools (EN)
      • kubectl Cheat Sheet
    • Đóng góp
      • Contribute to Kubernetes Documentation (EN)
      • Contributing to Kubernetes blogs (EN)
        • Submitting articles to Kubernetes blogs (EN)
        • Blog guidelines (EN)
        • Blog article mirroring (EN)
        • Post-release communications (EN)
        • Helping as a blog writing buddy (EN)
      • Suggesting content improvements (EN)
      • Contributing new content (EN)
        • Opening a pull request (EN)
        • Documenting for a release (EN)
        • Case studies (EN)
      • Reviewing changes (EN)
        • Reviewing pull requests (EN)
        • For approvers and reviewers (EN)
      • Localizing Kubernetes documentation (EN)
      • Participating in SIG Docs (EN)
        • Roles and responsibilities (EN)
        • Issue Wranglers (EN)
        • PR wranglers (EN)
      • Documentation style overview (EN)
        • Content guide (EN)
        • Style guide (EN)
        • Diagram guide (EN)
        • Writing a new topic (EN)
        • Page content types (EN)
        • Content organization (EN)
        • Custom Hugo Shortcodes (EN)
      • Updating Reference Documentation (EN)
        • Quickstart (EN)
        • Contributing to the Upstream Kubernetes Code (EN)
        • Generating Reference Documentation for the Kubernetes API (EN)
        • Generating Reference Documentation for kubectl Commands (EN)
        • Generating Reference Documentation for Metrics (EN)
        • Generating Reference Pages for Kubernetes Components and Tools (EN)
        • (EN)
      • Advanced contributing (EN)
      • Viewing Site Analytics (EN)
    • Docs smoke test page (EN)
Cài đặt và cấu hình kubectl

Công cụ command-line trong Kubernetes, kubectl, cho phép bạn thực thi các câu lệnh trong Kubernetes clusters. Bạn có thể sử dụng kubectl để triển khai các ứng dụng, theo dõi và quản lý tài nguyên của cluster, và xem log. Để biết các thao tác của kubectl, truy cập tới Tổng quan về kubectl.

Trước khi bạn bắt đầu

Bạn cần phải sử dụng phiên bản kubectl sai lệch không quá một phiên bản với version của cluster. Ví dụ, một client v1.2 nên được hoạt động với master v1.1, v1.2 và v1.3. Sử dụng phiên bản mới nhất của kubectl giúp tránh được các vấn đề không lường trước được.

Cài đặt kubectl trên Linux

Cài đặt kubectl binary với curl trên Linux

  1. Tải về phiên bản mới nhất với câu lệnh:

    curl -LO https://dl.k8s.io/release/`curl -LS https://dl.k8s.io/release/stable.txt`/bin/linux/amd64/kubectl

    Để tải về phiên bản cụ thể, hãy thay thế phần $(curl -LS https://dl.k8s.io/release/stable.txt) trong câu lệnh với một phiên bản cụ thể.

    Ví dụ như, để tải về phiên bản 1.34.0 trên Linux, hãy nhập như sau:

    curl -LO https://dl.k8s.io/release/v1.34.0/bin/linux/amd64/kubectl
  2. Tạo kubectl binary thực thi.

    chmod +x ./kubectl
  3. Đưa bản binary vào biến môi trường PATH của bạn.

    sudo mv ./kubectl /usr/local/bin/kubectl
  4. Kiểm tra chắc chắn rằng phiên bản bạn cài là mới nhất:

    kubectl version

Cài đặt kubectl sử dụng trình quản lý gói

sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl gnupg sudo mkdir -p -m 755 /etc/apt/keyrings curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg sudo chmod 644 /etc/apt/keyrings/kubernetes-apt-keyring.gpg echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.33/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list sudo apt-get update sudo apt-get install -y kubectl

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/ enabled=1 gpgcheck=1 gpgkey=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/repodata/repomd.xml.key EOF sudo yum install -y kubectl

Cài đặt với snap

Nếu bạn đang sử dụng Ubuntu hoặc distro Linux khác hỗ trợ trình quản lý gói snap, thì kubectl đã có sẵn trong snap.

  1. Chuyển sang user snap và thực thi câu lệnh cài đặt:

    sudo snap install kubectl --classic
  2. Kiểm tra phiên bản bạn vừa cài là mới nhất:

    kubectl version

Cài đặt kubectl trên macOS

Cài đặt kubectl binary với curl trên macOS

  1. Tải về phiên bản mới nhất:

    curl -LO "https://dl.k8s.io/release/$(curl -LS https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl"

    Để tải về phiên bản cụ thể, hãy thay thế phần $(curl -LS https://dl.k8s.io/release/stable.txt) trong câu lệnh với phiên bản cụ thể.

    Ví dụ, để tải về phiên bản 1.34.0 trên macOS, gõ:

    curl -LO https://dl.k8s.io/release/v1.34.0/bin/darwin/amd64/kubectl
  2. Tạo kubectl binary thực thi.

    chmod +x ./kubectl
  3. Đưa bản binary vào biến môi trường PATH của bạn.

    sudo mv ./kubectl /usr/local/bin/kubectl
  4. Kiểm tra chắc chắn rằng phiên bản bạn cài là mới nhất:

    kubectl version

Cài đặt với Homebrew trên macOS

Nếu bạn đang trên macOS và sử dụng trình quản lý gói Homebrew, bạn có thể cài đặt kubectl với Homebrew.

  1. Chạy câu lệnh cài đặt:

    brew install kubectl

    hoặc

    brew install kubernetes-cli
  2. Kiểm tra chắc chắn rằng phiên bản bạn cài là mới nhất:

    kubectl version

Cài đặt với Macports trên macOS

Nếu bạn đang trên macOS và sử dụng trình quản lý gói Macports, bạn có thể cài đặt kubectl với Macports.

  1. Chạy câu lệnh cài đặt:

    sudo port selfupdate sudo port install kubectl
  2. Kiểm tra chắc chắn rằng phiên bản bạn cài là mới nhất:

    kubectl version

Cài đặt kubectl trên Windows

Cài đặt kubectl binary với curl trên Windows

  1. Tải về phiên bản mới nhất 1.34.0 từ đường dẫn này.

    Hoặc nếu bạn đã cài đặt curl, hãy sử dụng câu lệnh sau:

    curl -LO https://dl.k8s.io/release/v1.34.0/bin/windows/amd64/kubectl.exe

    Để tìm ra phiên bản ổn định mới nhất, hãy xem https://dl.k8s.io/release/stable.txt.

  2. Đưa bản binary vào biến môi trường PATH của bạn.

  3. Kiểm tra chắn chắn phiên bản kubectl giống với bản đã tải về:

    kubectl version

Lưu ý:

Docker Desktop cho Windows thêm phiên bản kubectl riêng của nó vào PATH. Nếu bạn đã cài đặt Docker Desktop trước đây, bạn có thể cần đặt đường dẫn PATH của bạn trước khi bản cài đặt Docker Desktop thêm 1 PATH vào hoặc loại bỏ kubectl của Docker Desktop.

Cài đặt với Powershell từ PSGallery

Nếu bạn đang ở trên Windows và sử dụng trình quản lý gói Powershell Gallery, bạn có thể cài đặt và cập nhật kubectl với Powershell.

  1. Thực thi các câu lệnh cài đặt sau (hãy đảm bảo bạn tự định nghĩa DownloadLocation):

    Install-Script -Name install-kubectl -Scope CurrentUser -Force install-kubectl.ps1 [-DownloadLocation <path>]

    Lưu ý:

    Nếu bạn không định nghĩa DownloadLocation, kubectl sẽ được cài đặt ở thư mục temp của user.

    Bản cài đặt sẽ tạo ra $HOME/.kube và hướng dẫn để tạo ra file cấu hình

  2. Kiểm tra chắc chắn rằng phiên bản bạn cài là mới nhất:

    kubectl version

    Lưu ý:

    Cập nhật của bản cài đặt sẽ được thực hiện khi chạy lại các câu lệnh từ bước 1.

Cài đặt trên Windows sử dụng Chocolatey hoặc Scoop

Để cài đặt kubectl trên Windows bạn có thể sử dụng trình quản lý gói Chocolatey hoặc bộ cài đặt câu lệnh Scoop.

choco install kubernetes-cli

scoop install kubectl 2. Kiểm tra chắc chắn rằng phiên bản bạn cài là mới nhất:

``` kubectl version ```
  1. Di chuyển tới thư mục home của bạn:

    cd %USERPROFILE%
  2. Tạo thư mục .kube:

    mkdir .kube
  3. Di chuyển tới thư mục .kube bạn vừa mới tạo:

    cd .kube
  4. Cấu hình kubectl để sử dụng Kubernetes cluster từ xa:

    New-Item config -type file

    Lưu ý:

    Chỉnh sửa file cấu hình với trình soạn thảo văn bản, như là Notepad.

Tải xuống từ một phần của Google Cloud SDK

Bạn có thể cài đặt kubectl từ một phần của Google Cloud SDK.

  1. Cài đặt Google Cloud SDK.

  2. Thực thi câu lệnh cài đặt kubectl:

    gcloud components install kubectl
  3. Kiểm tra chắc chắn rằng phiên bản bạn cài là mới nhất:

    kubectl version

Xác minh cấu hình kubectl

Để kubectl tìm kiếm và truy cập Kubernetes cluster, nó cần một kubeconfig file, được tự động tạo ra khi bạn tạo mới một cluster sử dụng kube-up.sh hoặc triển khai thành công một Minikube cluster. Mặc định thì cấu hình của kubectl được xác định tại ~/.kube/config.

Kiểm tra kubectl được cấu hình đúng bằng việc xem trạng thái của cluster:

kubectl cluster-info

Nếu bạn trông thấy một URL phản hồi, thì kubectl đã được cấu hình đúng để truy cập vào cluster của bạn.

Nếu bạn trông thấy một tin nhắn tương tự bên dưới, thì kuberctl chưa được cấu hình đúng hoặc chưa thể kết nối với Kubernetes cluster.

The connection to the server <server-name:port> was refused - did you specify the right host or port?

Ví dụ như, nếu bạn đang định chạy một Kubernetes cluster trên laptop của bạn (locally), bạn sẽ cần một công cụ như Minikube được cài trước đó và chạy lại các câu lệnh bên trên.

Nếu kubectl cluster-info trả về url nhưng bạn không thể truy cập vào cluster của bạn, thì hãy kiểm tra nó đã được cấu hình đúng hay chưa, bằng cách:

kubectl cluster-info dump

Các lựa chọn cấu hình kubectl

Kích hoạt shell autocompletion

kubectl cung cấp autocompletion hỗ trợ cho Bash and Zsh, giúp bạn giảm thiểu việc phải gõ nhiều câu lệnh.

Bên dưới đâu là các bước để thiết lập autocompletion cho Bash (bao gồm sự khác nhau giữa Linux và macOS) và Zsh.

Giới thiệu

Kubelet completion script cho Bash được tạo ra với câu lệnh kubectl completion bash. Sau khi script được tạo ra, bạn cần source (thực thi) script đó để kích hoạt tính năng autocompletion.

Tuy nhiên, completion script phụ thuộc vào bash-completion, nên bạn phải cài đặt bash-completion trước đó (kiểm tra bash-completion tồn tại với câu lệnh type _init_completion).

Cài đặt bash-completion

bash-completion được cung cấp bởi nhiều trình quản lý gói (xem tại đây). Bạn có thể cài đặt với lệnh apt-get install bash-completion hoặc yum install bash-completion.

Các lệnh trên tạo ra /usr/share/bash-completion/bash_completion, đây là script chính của bash-completion. Tùy thuộc vào trình quản lý gói của bạn, mà bạn phải source (thực thi) file này trong file ~/.bashrc.

Để tìm ra file này, reload lại shell hiện tại của bạn và chạy lệnh type _init_completion. Nếu thành công, bạn đã thiết lập xong, không thì hãy thêm đoạn sau vào file ~/.bashrc của bạn:

source /usr/share/bash-completion/bash_completion

Reload lại shell của bạn và xác nhận bash-completion được cài đặt đúng bằng lệnh type _init_completion.

Kích hoạt kubectl autocompletion

Bây giờ bạn cần đảm bảo rằng kubectl completion script được sourced trên tất cả các session của shell. Có 2 cách để làm việc này:

  • Source script trong file ~/.bashrc:

    echo 'source <(kubectl completion bash)' >>~/.bashrc
  • Thêm script vào thư mục /etc/bash_completion.d:

    kubectl completion bash >/etc/bash_completion.d/kubectl
  • Nếu bạn có một alias cho kubectl, bạn có thể thêm một shell completion nữa cho alias đó:

    echo 'alias k=kubectl' >>~/.bashrc echo 'complete -F __start_kubectl k' >>~/.bashrc

Lưu ý:

bash-completion sources tất cả completion scripts trong /etc/bash_completion.d.

Các cách trên đều hiệu quả tương đương nhau. Sau khi reload lại shell, kubectl autocompletion sẽ làm việc.

Giới thiệu

Kubectl completion script trên Bash được tạo ra bởi kubectl completion bash. Source script này sẽ kích hoạt tính năng kubectl completion.

Tuy nhiên, kubectl completion script phụ thuộc vào bash-completion mà bạn cài trước đó.

Cảnh báo:

Có 2 phiên bản của bash-completion là v1 và v2. V1 dành cho Bash 3.2 (Bash mặc định trên macOS), và v2 dành cho Bash 4.1+. Kubectl completion script không làm việc phù hợp với bash-completion v1 và Bash 3.2. Nó tương thích với bash-completion v2Bash 4.1+. Vì vậy, để sử dụng kubectl completion một cách chính xác trên macOS thì bạn phải cài đặt Bash 4.1+ (hướng dẫn). Hướng dẫn tiếp theo giả định rằng bạn đang sử dụng Bash 4.1+ (nghĩa là, bất kỳ phiên bản Bash nào từ 4.1 trở lên).

Cài đặt bash-completion

Lưu ý:

Như đã đề cập, những hướng dẫn này giả định bạn đang sử dụng Bash 4.1+, có nghĩa rằng bạn sẽ cài đặt bash-completion v2 (trái ngược với Bash 3.2 và bash-completion v1, trong trường hợp đó, kubectl completion sẽ không hoạt động).

Bạn có thể kiểm tra bash-completion v2 đã cài đặt trước đó chưa với lệnh type _init_completion. Nếu chưa, bạn có thể cài đặt nó với Homebrew:

brew install bash-completion@2

Từ đầu ra của lệnh này, hãy thêm đoạn sau vào file ~/.bashrc của bạn:

export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d" [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

Tải lại shell của bạn và xác minh rằng bash-completion v2 được cài đặt chính xác chưa bằng lệnh type _init_completion.

Kích hoạt kubectl autocompletion

Bây giờ bạn phải đảm bảo rằng kubectl completion script đã được sourced trong tất cả các phiên shell của bạn. Có nhiều cách để đạt được điều này:

  • Source completion script trong file ~/.bashrc:

    echo 'source <(kubectl completion bash)' >>~/.bashrc
  • Thêm completion script vào thư mục /usr/local/etc/bash_completion.d:

    kubectl completion bash >/usr/local/etc/bash_completion.d/kubectl
  • Nếu bạn có alias cho kubectl, bạn có thể mở rộng shell completion để làm việc với alias đó:

    echo 'alias k=kubectl' >>~/.bashrc echo 'complete -F __start_kubectl k' >>~/.bashrc
  • Nếu bạn đã cài kubectl với Homebrew (như đã giới thiệu bên trên)) thì kubectl completion script sẽ có trong /usr/local/etc/bash_completion.d/kubectl. Trong trường hợp này thì bạn không cần làm gì cả.

Lưu ý:

Cài đặt theo cách Homebrew đã source tất cả các tệp trong thư mục BASH_COMPLETION_COMPAT_DIR, đó là lý do tại sao hai phương thức sau hoạt động.

Trong mọi trường hợp, sau khi tải lại shell của bạn, kubectl completion sẽ hoạt động.

Kubectl completion script cho Zsh được tạo ra với lệnh kubectl completion zsh. Source completion script trong shell của bạn sẽ kích hoạt kubectl autocompletion.

Để nó hoạt động cho tất cả các shell, thêm dòng sau vào file ~/.zshrc:

source <(kubectl completion zsh)

Nếu bạn có alias cho kubectl, bạn có thể mở rộng shell completion để làm việc với alias đó:

echo 'alias k=kubectl' >>~/.zshrc echo 'compdef __start_kubectl k' >>~/.zshrc

Sau khi tải lại shell, kubectl autocompletion sẽ hoạt động.

Nếu bạn nhận được lỗi complete:13: command not found: compdef, thêm dòng sau vào đầu file ~/.zshrc:

autoload -Uz compinit compinit

Tiếp theo là gì

  • Cài đặt Minikube
  • Xem hướng dẫn bắt đầu để biết thêm về việc tạo cluster.
  • Tìm hiểu cách khởi chạy và hiển thị ứng dụng của bạn.
  • Nếu bạn cần quyền truy cập vào một cluster mà bạn không tạo, hãy xem tài liệu Sharing Cluster Access.
  • Đọc tài liệu tham khảo của kubectl

Phản hồi

Có Không

Cảm ơn bạn đã phản hồi. Nếu bạn có một câu hỏi cụ thể và có thể trả lời về cách sử dụng Kubernetes, hãy đặt nó trên Stack Overflow. Mở một vấn đề trong Kho GitHub nếu bạn muốn báo cáo một vấn đề hoặc đề xuất một cải tiến.

Last modified August 25, 2025 at 4:40 AM PST: [vi] Update kubectl install steps to pkgs.k8s.io (0f1e55f897) Edit this page Create child page Tạo một vấn đề Print entire section
  • Trước khi bạn bắt đầu
  • Cài đặt kubectl trên Linux
    • Cài đặt kubectl binary với curl trên Linux
    • Cài đặt kubectl sử dụng trình quản lý gói
    • Cài đặt với snap
  • Cài đặt kubectl trên macOS
    • Cài đặt kubectl binary với curl trên macOS
    • Cài đặt với Homebrew trên macOS
    • Cài đặt với Macports trên macOS
  • Cài đặt kubectl trên Windows
    • Cài đặt kubectl binary với curl trên Windows
    • Cài đặt với Powershell từ PSGallery
    • Cài đặt trên Windows sử dụng Chocolatey hoặc Scoop
  • Tải xuống từ một phần của Google Cloud SDK
  • Xác minh cấu hình kubectl
  • Các lựa chọn cấu hình kubectl
    • Kích hoạt shell autocompletion
  • Tiếp theo là gì

Từ khóa » Tải 1path Connect