使用AWS-EKS服务搭建TiDB数据库
发表于:2023-07-17 14:59:49浏览:260次
一、创建EKS
1.创建 集群和服务器节点 使用的 IAM-role(也可以系统自动创建,控制面板中操作建议自己建)
cluster 的 role :
需要添加权限j角色(Permissions)- AmazonEKSClusterPolicy ,可信实体(Trust relationships)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
node 的 role :
需要添加权限角色(Permissions)- AmazonEC2ContainerRegistryReadOnly、AmazonEKS_CNI_Policy、AmazonEKSWorkerNodePolicy ,可信实体(Trust relationships)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "eks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
2.创建 EKS 集群,(如果使用EKSCTL配置创建 也可以吧 nodegroup 分开)
控制面板中制定,名称、版本、cluster IAM-role 、VPC 、subnet 、security group(我们自定义的安全组,可以控制我们堡垒机来访问它)、Choose cluster IP address family(IPV4、IPV6)、cluster endpoint access( public、purblic and priavet、privavet)、logs、Amazon EKS add-ons(AWS 的 EKS 组建)最后确定创建,一般要 5-10分钟
一、创建 storageclass \动态pvc
前置条件 1.是否拥有集群的 OIDC 提供商 ID
##1.先查询出你的 集群 ID (dev-eks-tidb 替换你的集群名称)
oidc_id=$(aws eks describe-cluster --name dev-eks-tidb --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
##2.查询出结果如果有 你的ID显示 说明你拥有,跳过创建步骤
aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4
##3. 如果步骤2 中没有ID出现,你需要创建
eksctl utils associate-iam-oidc-provider --cluster dev-eks-tidb --approve
开始安装 Amazon EBS CSI 驱动程序(见AWS文档)—1.27 EKS版本可以手动选择 插件,但是 IODC还是得自己验证是否启用,以及IAM配置
开始安装TIDB
#下载安装文档yaml 文件
curl -O https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.6/examples/aws/tidb-cluster.yaml && \
curl -O https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.6/examples/aws/tidb-monitor.yaml && \
curl -O https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.6/examples/aws/tidb-dashboard.yaml
注意自己创建 nodegroup 的时候 指定的 lables 和 tolerations 污点,
nodeSelector:
dedicated: tidb-pd
tolerations:
- effect: NoSchedule
key: dedicated
operator: Equal
value: tidb-pd
#创建gp3磁盘,先设置 ebs-csi-node toleration。(输出:daemonset.apps/ebs-csi-node patched)
kubectl patch -n kube-system ds ebs-csi-node -p '{"spec":{"template":{"spec":{"tolerations":[{"operator":"Exists"}]}}}}'
创建ebs-gp3.yaml 内容如下
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: gp3
provisioner: ebs.csi.aws.com
allowVolumeExpansion: true
volumeBindingMode: WaitForFirstConsumer
parameters:
type: gp3
fsType: ext4
iops: "4000"
throughput: "400"
mountOptions:
- nodelalloc,noatime
#执行创建GP3磁盘
kubectl apply -f ebs-gp3.yml
#创建集群
kubectl create namespace tidb-cluster
#部署集群,如果用GP3的磁盘,自己去对应的 storageClassName 修改
kubectl apply -f tidb-cluster.yaml -n tidb-cluster
kubectl apply -f tidb-monitor.yaml -n tidb-cluster
##查看启动状态,如果是pending 状态 检查NODE是否建立,污点是否匹配上,磁盘是否创建,
kubectl get pods -n tidb-cluster