在 DigitalOcean 上开始使用 kOps ¶
警告:kOps 上的 DigitalOcean 支持已升级为**beta**,这意味着它处于良好状态,可以用于生产。但是,它不像稳定的云提供商那样经过严格测试,并且可能缺少一些功能。
要求 ¶
- 已安装 kops 版本 >= 1.9
- 已安装 kubectl
- DigitalOcean 帐户
- DigitalOcean 访问令牌
- 带有 API 密钥的 DigitalOcean Spaces 存储桶
- DigitalOcean 域名。要将您的域名注册商指向 DigitalOcean 的名称服务器,请遵循本指南
- 设置您的 SSH 密钥
环境变量 ¶
设置以下环境变量非常重要
export KOPS_STATE_STORE=do://<bucket-name> # where <bucket-name> is the name of the bucket you set earlier
export DIGITALOCEAN_ACCESS_TOKEN=<access-token> # where <access-token> is the access token generated earlier to use the V2 API
# DigitalOCcean Spaces is S3 compatible so we just override some S3 configurations to talk to our bucket
export S3_ENDPOINT=nyc3.digitaloceanspaces.com # this can also be ams3.digitaloceanspaces.com or sgp1.digitaloceanspaces.com depending on where you created your Spaces bucket
export S3_ACCESS_KEY_ID=<access-key-id> # where <access-key-id> is the Spaces API Access Key for your bucket
export S3_SECRET_ACCESS_KEY=<secret-key> # where <secret-key> is the Spaces API Secret Key for your bucket
创建单主节点集群 ¶
在以下示例中,应将 example.com
替换为您在完成要求时创建的 DigitalOcean 域名。请注意,kOps 只能成功在支持块存储的区域 (AMS3、BLR1、FRA1、LON1、NYC1、NYC3、SFO3、SGP1 和 TOR1) 中配置集群。
# debian (the default) + flannel overlay cluster in tor1
kops create cluster --cloud=digitalocean --name=my-cluster.example.com --networking=flannel --zones=tor1 --ssh-public-key=~/.ssh/id_rsa.pub
kops update cluster my-cluster.example.com --yes
# ubuntu + calico overlay cluster in nyc1 using larger droplets
kops create cluster --cloud=digitalocean --name=my-cluster.example.com --image=ubuntu-16-04-x64 --networking=calico --zones=nyc1 --ssh-public-key=~/.ssh/id_rsa.pub --node-size=s-8vcpu-32gb
kops update cluster my-cluster.example.com --yes
# debian + flannel overlay cluster in ams3 using optimized droplets
kops create cluster --cloud=digitalocean --name=my-cluster.example.com --image=debian-9-x64 --networking=flannel --zones=ams3 --ssh-public-key=~/.ssh/id_rsa.pub --node-size=c-4
kops update cluster my-cluster.example.com --yes
# to validate a cluster
kops validate cluster my-cluster.example.com
# to delete a cluster
kops delete cluster my-cluster.example.com --yes
# to export kubecfg
* follow steps as mentioned [here](https://kops.kubernetes.ac.cn/cli/kops_export_kubeconfig/#examples).
# to update a cluster
* follow steps as mentioned [here](https://kops.kubernetes.ac.cn/operations/updates_and_upgrades/#manual-update)
# to install csi driver for DO block storage
* follow steps as mentioned [here](https://github.com/digitalocean/csi-digitalocean#installing-to-kubernetes)
创建多主节点高可用集群 ¶
在以下示例中,应将 dev5.k8s.local
替换为任何以 .k8s.local
结尾的集群名称,以便创建基于 Gossip 的集群。确保主节点数量为奇数。负载均衡器将动态创建,面向主节点实例。
# debian (the default) + flannel overlay cluster in tor1 with 3 master setup and a public load balancer.
kops create cluster --cloud=digitalocean --name=dev5.k8s.local --networking=cilium --api-loadbalancer-type=public --master-count=3 --zones=tor1 --dns none --ssh-public-key=~/.ssh/id_rsa.pub --yes
# to delete a cluster - this will also delete the load balancer associated with the cluster.
kops delete cluster dev5.k8s.local --yes
VPC 支持 ¶
如果您已经创建了 VPC 并希望在该 VPC 中运行 kops 集群,请指定 VPC 的 UUID,如下所示。
/kops create cluster --cloud=digitalocean --name=dev1.example.com --vpc=af287488-862e-46c7-a783-5e5fa89cb200 --networking=cilium --zones=tor1 --ssh-public-key=~/.ssh/id_rsa.pub
如果您想为运行 kops 集群创建一个新的 VPC,请指定网络 CIDR,如下所示。
./kops create cluster --cloud=digitalocean --name=dev1.example.com --networking=calico --network-cidr=192.168.11.0/24 --zones=nyc1 --ssh-public-key=~/.ssh/id_rsa.pub --yes
仍在开发的功能 ¶
DigitalOcean 的 kOps 目前不支持以下功能
- DO 的 kops terraform 支持
下一步 ¶
现在您已拥有一个正常工作的 kOps 集群,请阅读生产环境设置指南,以了解有关如何为生产工作负载配置 kOps 的更多信息。