【发布时间】:2021-08-12 10:13:41
【问题描述】:
我正在尝试编写一个 Jinja 模板和一个 bash 脚本来创建一个私有 GKE 集群,并带有一个选项(在我的 bash 脚本中),以允许它访问私有和公共端点。。 p>
所以我希望我的 bash 脚本在默认情况下使该集群具有私有端点访问权限,并且当用户使用标志 (deployment.sh --public-endpoint) 运行时使其具有公共端点访问权限。
这是我的 Jinja 模板的样子:
resources:
- name: {{ CLUSTER_NAME }}
type: container.v1.cluster
properties:
zone: {{ properties["zone"] }}
cluster:
name: {{ CLUSTER_NAME }}
description: Customer Stack Cluster
network: {{properties["network"]}}
subnetwork: {{properties["subnetwork"]}}
*privateClusterConfig:
enablePrivateNodes: true
enablePrivateEndpoint: true
**{% if --public-endpoint flag was passed %}
<p> Make it with a public endpoint access </p>
{% else %}
<p> make it with private endpoint access </p>
{% endif %}***
# Configure the IP range for the hosted master network
masterIpv4CidrBlock: 172.16.0.32/28
ipAllocationPolicy:
useIpAliases: true
nodePools:
- name: nodepool
config:
oauthScopes:
- https://www.googleapis.com/auth/compute
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring
- https://www.googleapis.com/auth/devstorage.full_control
machineType: n1-standard-2
# Default will be passed in
serviceAccount: {{ properties['computeServiceAccount'] }}
autoscaling:
enabled: true
minNodeCount: 2
maxNodeCount: 5
initialNodeCount: 2
我的 bash 脚本的那部分如下所示:
CLUSTER=$(gcloud deployment-manager deployments create "${NAME}" --template deployment.jinja --properties "region:${REGION},zone:${ZONE},network:${NETWORK},subnetwork:${SUBNETWORK},computeServiceAccount:${COMPUTE_SA},k8sVersion:\"${K8S_VERSION}\"" --format=json)
if [ $? -ne 0 ]; then error "FAILED_DEPLOY_GKE"; fi
我不知道如何使这项工作以及 Jinja 中的 if 语句语法如何。
【问题讨论】:
-
如果您想为某些私有节点提供出站互联网访问,您可以使用 Cloud NAT 或管理您自己的 NAT 网关。请检查private clusters 因此,将不同的部署分开在两个不同的文件中可能更有意义,因为如果使用公共端点,您可能还必须设置 Cloud NAT 或自己的 NAT 网关。
-
“因为在使用公共端点的情况下,您可能还必须设置 Cloud NAT 或自己的 NAT 网关”——您的意思是私有端点?
-
是的,您是对的,将 Cloud NAT 网关设置为私有端点。您可能会在 Private Google Access Interaction 中找到更好的解释
标签: bash google-cloud-platform jinja2 google-kubernetes-engine gke-networking