Ich*_*hyo 5 aws-cli kubernetes boto3 amazon-eks
在使用 Amazon 的 K8s 产品(EKS服务)时,您有时需要将 Kubernetes API 和配置连接到 AWS 内建立的基础设施。特别是,我们需要一个kubeconfig用正确的凭据和URL连接到由EKS提供的K8S控制平面。
Amazon 命令行工具aws为此任务提供了一个例程
aws eks update-kubeconfig --kubeconfig /path/to/kubecfg.yaml --name <EKS-cluster-name>
Run Code Online (Sandbox Code Playgroud)
在查看Boto API 文档时,我似乎无法找到上述aws例程的等效项。也许我看错了地方。
aws在子进程中调用)?jax*_*orm 12
没有方法功能可以做到这一点,但您可以像这样自己构建配置文件:
# Set up the client
s = boto3.Session(region_name=region)
eks = s.client("eks")
# get cluster details
cluster = eks.describe_cluster(name=cluster_name)
cluster_cert = cluster["cluster"]["certificateAuthority"]["data"]
cluster_ep = cluster["cluster"]["endpoint"]
# build the cluster config hash
cluster_config = {
"apiVersion": "v1",
"kind": "Config",
"clusters": [
{
"cluster": {
"server": str(cluster_ep),
"certificate-authority-data": str(cluster_cert)
},
"name": "kubernetes"
}
],
"contexts": [
{
"context": {
"cluster": "kubernetes",
"user": "aws"
},
"name": "aws"
}
],
"current-context": "aws",
"preferences": {},
"users": [
{
"name": "aws",
"user": {
"exec": {
"apiVersion": "client.authentication.k8s.io/v1alpha1",
"command": "heptio-authenticator-aws",
"args": [
"token", "-i", cluster_name
]
}
}
}
]
}
# Write in YAML.
config_text=yaml.dump(cluster_config, default_flow_style=False)
open(config_file, "w").write(config_text)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3675 次 |
| 最近记录: |