限定公開クラスタは、内部 IP アドレスのみに依存する Virtual Private Cloud(VPC)ネイティブ クラスタです。つまり、デフォルトでノードと Pod はインターネットから隔離されています。このページでは、Cloud Code を使用して、パブリック エンドポイント アクセスの有無にかかわらず限定公開クラスタに接続し、限定公開クラスタが Google Cloudの外部からリソースにアクセスできるようにする方法について説明します。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-02-17 UTC。"],[[["\u003cp\u003ePrivate clusters isolate nodes and pods from the internet by default, relying on internal IP addresses within a Virtual Private Cloud (VPC).\u003c/p\u003e\n"],["\u003cp\u003eCloud Code connects to private clusters by setting the cluster address in the KubeConfig to either the external IP (if the public endpoint is enabled) or the internal VPC IP (if the public endpoint is disabled).\u003c/p\u003e\n"],["\u003cp\u003eTo connect to a private cluster, Cloud Code must be on a machine within the cluster's network or have network access, such as through a proxy server, Cloud Interconnect, or Cloud VPN.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code can configure a proxy server to route requests to a private cluster's control plane when the control plane API is not publicly available.\u003c/p\u003e\n"],["\u003cp\u003eCloud Code allows the configuration of Cloud NAT to enable outbound internet connections from private clusters to access APIs and image registries outside of Google Cloud.\u003c/p\u003e\n"]]],[],null,["# Configure a private cluster in Cloud Code for VS Code\n\nA *private cluster* is a Virtual Private Cloud (VPC)-native cluster that only\ndepends on [internal IP addresses](/kubernetes-engine/docs/concepts/alias-ips#internal_ip_addresses).\nThis means that nodes and pods are isolated from the internet by default. This\npage explains how to use Cloud Code to connect to private\nclusters with and without public endpoint access and permit private clusters to\naccess resources from outside Google Cloud.\n\nFor information about private clusters, see\n[Private clusters](/kubernetes-engine/docs/concepts/private-cluster-concept).\nFor steps to configure private clusters, see\n[Creating a private cluster](/kubernetes-engine/docs/how-to/private-clusters).\n\nAdd a private GKE cluster to your KubeConfig\n--------------------------------------------\n\nAdding a private cluster in Cloud Code has the following behavior:\n\n- For clusters that have the public endpoint enabled, adding the cluster sets\n the cluster address in the KubeConfig to the external IP.\n\n- For clusters that have the public endpoint turned off, adding the cluster sets\n the cluster address in the KubeConfig to be the internal VPC IP of the\n cluster.\n\nTo add an authorized network to an existing cluster, make sure you are connected\nto an authorized network, as this cluster has [authorized networks enabled](/kubernetes-engine/docs/how-to/authorized-networks#add).\n\nTo learn more about connecting to VMs without external IP addresses, see\n[Securely connecting to VM instances](/solutions/connecting-securely#external).\nTo manage/delete the instances that you created, see\n[VM instances](https://console.cloud.google.com/compute/instances).\n\nTo successfully connect to the private cluster, Cloud Code must be\nrunning on a machine in the cluster's network or be able to access the cluster's\nnetwork, such as by using a proxy server, Cloud Interconnect, or\nCloud VPN.\n\nFor steps to create GKE clusters in Cloud Code\nand add existing GKE clusters to Cloud Code, see\n[create and configure a GKE cluster](/code/docs/vscode/create-configure-gke-cluster).\nCloud Code opens the Google Cloud console to create your cluster.\n\nAfter you create the cluster, [configure Cloud NAT](/nat/docs/gke-example?_ga=2.200274222.-1614030937.1640827593#gcloud)\nto enable outbound internet connections from your cluster if this was not set up\nduring cluster creation. To manage/delete the networks that you created, see\n[VPC networks](https://console.cloud.google.com/networking/networks/list).\n\nTroubleshoot issues connecting to private clusters\n--------------------------------------------------\n\nIf your dev environment isn't configured correctly to access a private cluster,\nrecommendations about how to resolve the issue appear in the following contexts:\n\n- In the expanded **Kubernetes** section, clusters that\n Cloud Code can't connect to appear with an error icon next to\n the cluster name. To view possible workarounds and a longer explanation of the\n potential issue, click the cluster name.\n\n- When you try to run operations on a cluster that's inaccessible because of\n potential issues with the private cluster's configuration, a notification\n displays an error message with a longer explanation of the potential issue and\n potential workarounds.\n\nConfigure a proxy server for a cluster\n--------------------------------------\n\nIf the\n[control plane API](https://kubernetes.io/docs/concepts/overview/kubernetes-api/)\nisn't available publicly, such as in a GKE cluster with public\nendpoint turned off, you can configure Cloud Code to proxy\nrequests to the control plane through a proxy server on the same network or VPC\nas the cluster:\n\n1. Configure a proxy server on the same network as your cluster if you haven't already. For steps to set up a Compute Engine VM as a basic proxy server, see [Remotely access a private cluster using a bastion host](/kubernetes-engine/docs/tutorials/private-cluster-bastion). For additional details, see [Creating Google Kubernetes Engine private clusters with network proxies for controller access](/architecture/creating-kubernetes-engine-private-clusters-with-net-proxies).\n2. Right-click the name of a cluster you've [added to Cloud Code](#private) and then click **Set up Kubectl Proxying for cluster** . Follow the prompts to enter the name of your proxy server, which is stored in the cluster's `proxy-url` field. The Kubernetes view reloads to display the connected cluster.\n\n### Cancel Kubernetes proxying\n\nRight-click the name of a cluster you've configured for Kubernetes proxying and\nthen click **Cancel Kubectl Proxying for cluster** . Cloud Code\nstops proxying requests for the cluster by unsetting the `proxy-url` field\nin the KubeConfig.\n\nAccess resources outside Google Cloud from clusters\n---------------------------------------------------\n\nAll configurations of GKE private clusters don't provide nodes\nwith internet access. As a result, clusters can't reach APIs on the public\ninternet. Clusters are automatically configured with\n[Private Google Access](/vpc/docs/private-google-access),\nwhich, for example, permits clusters to pull images from Artifact Registry. APIs and\nimage registries outside of Google Cloud are inaccessible without\nadditional configuration to allow outbound internet connections from the nodes.\nTo provide these connections, you can set up\n[Cloud NAT](/nat/docs/overview#NATwithGKE) on your VPC from\nCloud Code:\n\n1. Run the **Grant private GKE nodes outbound internet access** command, either by right-clicking a cluster or from the command palette (press `Ctrl`/`Cmd`+`Shift`+`P` or click **View** \\\u003e **Command Palette**).\n2. In the terminal, edit the [`gcloud compute routers create`](/sdk/gcloud/reference/compute/routers/create) and [`gcloud beta compute routers nats create`](/sdk/gcloud/reference/beta/compute/routers/nats/create) commands to specify the values for your application.\n3. To run the commands, press `Enter`.\n4. To manage/delete the routers that you created, see [Cloud Routers](https://console.cloud.google.com/hybrid/routers/list).\n\nWhat's next\n-----------\n\n- Learn about [Shared Virtual Private Cloud networks](/vpc/docs/shared-vpc).\n\nGet Support\n-----------\n\nTo send feedback, report issues on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues), or ask a question on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=cloud-code-vscode)."]]