如何在自建集群中部署cloud-provider-alibaba-cloud

简介: 前提条件 Kubernetes集群已经部署完毕 Master节点已经添加node-role.kubernetes.io/master: "" 标签 部署Cloud Controller Manager 配置Kubelet 为Kubelet配置ProviderID (需要为集群中所有节点执行此操作) META_EP=http://100.100.100.200/latest/me

前提条件

  • Kubernetes集群已经部署完毕
  • Master节点已经添加node-role.kubernetes.io/master: "" 标签

部署Cloud Controller Manager

配置Kubelet

为Kubelet配置ProviderID (需要为集群中所有节点执行此操作)

META_EP=http://100.100.100.200/latest/meta-data
echo `curl -s $META_EP/region-id`.`curl -s $META_EP/instance-id`
## for example
cn-shanghai.i-ufxxxxxxxxkb6xxo

为Node添加ProviderID

kubectl patch node xxxx -p '{"spec":{"providerID":"cn-shanghai.i-ufxxxxxxxxkb6xxo"}}'

设置AK

1)获取AK信息

2)对AK信息进行base64加密

echo -n "xxxxxxxxxxx" | base64

3)创建ConfigMap

apiVersion: v1
kind: ConfigMap
metadata:
  name: cloud-config
  namespace: kube-system
data:
  cloud-config.conf: |-
    {
        "Global": {
            "accessKeyID": "$Base64AccessKeyID",
            "accessKeySecret": "$Base64AccessKeySecret"
        }
    }

创建cloud-controller-manager.conf (需要在所有Master节点上执行)

将下述文件保存为 /etc/kubernetes/cloud-controller-manager.conf

其中, $CA_DATAcat /etc/kubernetes/pki/ca.crt|base64 -w 0 的执行结果,

server地址为集群的apiserver地址。

kind: Config
contexts:
- context:
    cluster: kubernetes
    user: system:cloud-controller-manager
  name: system:cloud-controller-manager@kubernetes
current-context: system:cloud-controller-manager@kubernetes
users:
- name: system:cloud-controller-manager
  user:
    tokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: $CA_DATA
    server: https://192.168.1.76:6443
  name: kubernetes

创建cloud-controller-manager

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: system:cloud-controller-manager
rules:
  - apiGroups:
      - ""
    resources:
      - persistentvolumes
      - services
      - secrets
      - endpoints
      - serviceaccounts
    verbs:
      - get
      - list
      - watch
      - create
      - update
      - patch
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - get
      - list
      - watch
      - delete
      - patch
      - update
  - apiGroups:
      - ""
    resources:
      - services/status
    verbs:
      - update
      - patch
  - apiGroups:
      - ""
    resources:
      - nodes/status
    verbs:
      - patch
      - update
  - apiGroups:
      - ""
    resources:
      - events
      - endpoints
    verbs:
      - create
      - patch
      - update
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: cloud-controller-manager
  namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: system:cloud-controller-manager
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:cloud-controller-manager
subjects:
- kind: ServiceAccount
  name: cloud-controller-manager
  namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: system:shared-informers
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:cloud-controller-manager
subjects:
- kind: ServiceAccount
  name: shared-informers
  namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: system:cloud-node-controller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:cloud-controller-manager
subjects:
- kind: ServiceAccount
  name: cloud-node-controller
  namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: system:pvl-controller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:cloud-controller-manager
subjects:
- kind: ServiceAccount
  name: pvl-controller
  namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: system:route-controller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:cloud-controller-manager
subjects:
- kind: ServiceAccount
  name: route-controller
  namespace: kube-system
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  labels:
    app: cloud-controller-manager
    tier: control-plane
  name: cloud-controller-manager
  namespace: kube-system
spec:
  selector:
    matchLabels:
      app: cloud-controller-manager
      tier: control-plane
  template:
    metadata:
      labels:
        app: cloud-controller-manager
        tier: control-plane
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
    spec:
      serviceAccountName: cloud-controller-manager
      tolerations:
      - effect: NoSchedule
        operator: Exists
        key: node-role.kubernetes.io/master
      - effect: NoSchedule
        operator: Exists
        key: node.cloudprovider.kubernetes.io/uninitialized
      nodeSelector:
         node-role.kubernetes.io/master: ""
      containers:
      - command:
        -  /cloud-controller-manager
        - --kubeconfig=/etc/kubernetes/cloud-controller-manager.conf
        - --address=127.0.0.1
        - --allow-untagged-cloud=true
        - --leader-elect=true
        - --cloud-provider=alicloud
        - --use-service-account-credentials=true
        - --cloud-config=/etc/kubernetes/config/cloud-config.conf
        ## 配置路由信息(Flannel网络插件)
        - --configure-cloud-routes=true
        - --allocate-node-cidrs=true
        - --route-reconciliation-period=3m
         # 替换为集群的podcidr
        - --cluster-cidr=172.20.0.0/16
        # 配置路由信息(Terway网络插件)
        #- --configure-cloud-routes=false
        #- --allocate-node-cidrs=false
        image: registry-vpc.${your-region}.aliyuncs.com/acs/cloud-controller-manager-amd64:v1.9.3.339-g9830b58-aliyun
        livenessProbe:
          failureThreshold: 8
          httpGet:
            host: 127.0.0.1
            path: /healthz
            port: 10258
            scheme: HTTP
          initialDelaySeconds: 15
          timeoutSeconds: 15
        name: cloud-controller-manager
        resources:
          requests:
            cpu: 200m
        volumeMounts:
        - mountPath: /etc/kubernetes/
          name: k8s
        - mountPath: /etc/ssl/certs
          name: certs
        - mountPath: /etc/pki
          name: pki
        - mountPath: /etc/kubernetes/config
          name: cloud-config
      hostNetwork: true
      volumes:
      - hostPath:
          path: /etc/kubernetes
        name: k8s
      - hostPath:
          path: /etc/ssl/certs
        name: certs
      - hostPath:
          path: /etc/pki
        name: pki
      - configMap:
          defaultMode: 420
          items:
          - key: cloud-config.conf
            path: cloud-config.conf
          name: cloud-config
        name: cloud-config

等待Pod running

kubectl -nkube-system get po|grep cloud-controller-manager

验证

1)创建deploy

kubectl create deploy nginx --image=nginx

2) 创建LoadBalancer类型svc

kubectl expose deploy nginx --name=test --port=80 --type=LoadBalancer

相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
相关文章
|
弹性计算 IDE 安全
Alibaba Cloud Toolkit:本地应用一键部署到任何机器上
Alibaba Cloud Toolkit:本地应用一键部署到任何机器上
1205 0
Alibaba Cloud Toolkit:本地应用一键部署到任何机器上
|
2月前
|
存储 Java Nacos
Spring Cloud+Nacos+KMS 动态配置最佳实践
本文讲述了 Spring Cloud 应用中结合 Nacos 实现了运行期配置动态更新的功能,以及在此基础上结合 KMS 在不改动代码的情况下对应用使用的敏感配置进行保护,解决将配置迁移到 Nacos 中可能存在的数据安全顾虑,并对其底层工作原理做了简单介绍。
505 14
|
负载均衡 Java 关系型数据库
|
Kubernetes 网络协议 安全
Spring Cloud Alibaba 应用如何平滑迁移至 IPv6?
一次性迁移不仅在基础设施层面不可行,对企业用户来说,就算基础设施都能准备完毕,让其将少则上百,多则成千上万的应用实例在一段时间内一次性停机进行协议栈迁移,无论是在风险上,还是成本上,对企业用户来说都是难以接受的!
303 8
Spring Cloud Alibaba 应用如何平滑迁移至 IPv6?
|
Nacos
Alibaba Nacos配置中心的使用
Alibaba Nacos配置中心的使用
197 0
|
SQL SpringCloudAlibaba 关系型数据库
SpringCloud Alibaba学习(三):Nacos之集群和持久化配置
SpringCloud Alibaba学习(三):Nacos之集群和持久化配置
206 1
SpringCloud Alibaba学习(三):Nacos之集群和持久化配置
|
Java 测试技术 Nacos
Spring Cloud Alibaba - 18 Nacos Config配置中心加载相同微服务的不同环境下的通用配置
Spring Cloud Alibaba - 18 Nacos Config配置中心加载相同微服务的不同环境下的通用配置
137 0
|
缓存 运维 容灾
Spring Cloud Alibaba - 17 Nacos Config 配置中心 应用篇
Spring Cloud Alibaba - 17 Nacos Config 配置中心 应用篇
594 0
|
负载均衡 算法 Java
Spring Cloud Alibaba - 12 使用Nacos的元数据实现金丝雀发布功能
Spring Cloud Alibaba - 12 使用Nacos的元数据实现金丝雀发布功能
436 0
|
Cloud Native Java 中间件
分布式组件:Spring Cloud Alibaba——Nacos注册中心
分布式组件:Spring Cloud Alibaba——Nacos注册中心
189 0
分布式组件:Spring Cloud Alibaba——Nacos注册中心

热门文章

最新文章