容器管理平台Rancher解析

2021-12-09 20:45:11 浏览数 (1)

Rancher是What?一个开源的企业级容器管理平台。通过Rancher,企业再也不必自己使用一系列的开源软件去从头搭建容器服务平台。Rancher提供了在生产环境中使用的管理Docker和Kubernetes的全栈化容器部署与管理平台。

Rancher体系主要基于以下四个部分组成:

  • 基础设施编排

Rancher可以使用任何公有云或者私有云的Linux主机资源。Linux主机可以是虚拟机,也可以是物理机。Rancher仅需要主机有CPU,内存,本地磁盘和网络资源。从Rancher的角度来说,一台云厂商提供的云主机和一台自己的物理机是一样的。Rancher为运行容器化的应用实现了一层灵活的基础设施服务。Rancher的基础设施服务包括网络, 存储, 负载均衡, DNS和安全模块。Rancher的基础设施服务也是通过容器部署的,所以同样Rancher的基础设施服务可以运行在任何Linux主机上。

  • 容器编排与调度

很多用户都会选择使用容器编排调度框架来运行容器化应用。Rancher包含了当前全部主流的编排调度引擎,例如Docker Swarm, Kubernetes, 和Mesos。同一个用户可以创建Swarm或者Kubernetes集群。并且可以使用原生的Swarm或者Kubernetes工具管理应用。除了Swarm,Kubernetes和Mesos之外,Rancher还支持自己的Cattle容器编排调度引擎。Cattle被广泛用于编排Rancher自己的基础设施服务以及用于Swarm集群,Kubernetes集群和Mesos集群的配置,管理与升级。

  • 应用商店

Rancher的用户可以在应用商店里一键部署由多个容器组成的应用。用户可以管理这个部署的应用,并且可以在这个应用有新的可用版本时进行自动化的升级。Rancher提供了一个由Rancher社区维护的应用商店,其中包括了一系列的流行应用。Rancher的用户也可以创建自己的私有应用商店。

  • 企业级权限管理

Rancher支持灵活的插件式的用户认证。支持Active Directory,LDAP, Github等 认证方式。Rancher支持在环境级别的基于角色的访问控制 (RBAC),可以通过角色来配置某个用户或者用户组对开发环境或者生产环境的访问权限。

Rancher Server 体系主要由认证代理(Authentication Proxy)、Rancher API Server、集群控制器(Cluster Controller)、etcd 节点和集群 Agent(Cluster Agent) 组成。除了集群 Agent 以外,其他组件都部署在 Rancher Server 中。简要架构如下图所示:

Rancher安装部署较为简单,具体如下所示:

代码语言:javascript复制
[administrator@JavaLangOutOfMemory ~ ]% sudo docker run -d --restart=unless-stopped -p 8080:8080 --name rancher-luga rancher/server
Unable to find image 'rancher/server:latest' locally
latest: Pulling from rancher/server
bae382666908: Pull complete 
29ede3c02ff2: Pull complete 
da4e69f33106: Pull complete 
8d43e5f5d27f: Pull complete 
b0de1abb17d6: Pull complete 
... ... 
Digest: sha256:95b55603122c28baea4e8d94663aa34ad770bbc624a9ed6ef986fb3ea5224d91
Status: Downloaded newer image for rancher/server:latest
cd80c879275444f95355f07b69651310b98eec80f30729199732acce6e463188
代码语言:javascript复制
[administrator@JavaLangOutOfMemory ~ ]% sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                              NAMES
cd80c8792754        rancher/server      "/usr/bin/entry /usr…"   About a minute ago   Up About a minute   3306/tcp, 0.0.0.0:8080->8080/tcp  rancher-luga
[root@k8s-node01 ~]# curl -i http://127.0.0.1:8080/
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Fri, 29 Jan 2021 14:37:08 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: PL=rancher;Path=/
Vary: Accept-Encoding, User-Agent
X-Api-Account-Id: 1a1
X-Api-Account-Kind: admin
X-Api-Account-Name: admin
X-Api-Client-Ip: 172.17.0.1
X-Api-Schemas: http://127.0.0.1:8080/v1/schemas
X-Api-User-Id: 1a1
X-Rancher-Version: v1.6.30
Transfer-Encoding: chunked

{"id":"v1","type":"apiVersion","links":{"accounts":"http://127.0.0.1:8080/v1/accounts","agents":"http://127.0.0.1:8080/v1/agents","apiKeys":"http://127.0.0.1:8080/v1/apikeys","auditLogs":"http://127.0.0.1:8080/v1/auditlogs","azureadconfigs":"http://127.0.0.1:8080/v1/azureadconfigs","backupTargets":"http://127.0.0.1:8080/v1/backuptargets","backups":"http://127.0.0.1:8080/v1/backups","certificates":"http://127.0.0.1:8080/v1/certificates","composeProjects":"http://127.0.0.1:8080/v1/composeprojects","composeServices":"http://127.0.0.1:8080/v1/composeservices","configItemStatuses":"http://127.0.0.1:8080/v1/configitemstatuses","configItems":"http://127.0.0.1:8080/v1/configitems","containerEvents":"http://127.0.0.1:8080/v1/containerevents","containers":"http://127.0.0.1:8080/v1/containers","credentials":"http://127.0.0.1:8080/v1/credentials","databasechangeloglocks":"http://127.0.0.1:8080/v1/databasechangeloglocks","databasechangelogs":"http://127.0.0.1:8080/v1/databasechangelogs","dnsServices":"http://127.0.0.1:8080/v1/dnsservices","environments":"http:

通过上述操作,我们看到Rancher服务已启动,此时部署Agent,如下所示:

代码语言:javascript复制
[administrator@JavaLangOutOfMemory ~ ]% sudo docker run --rm --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v1.2.11 http://192.168.56.109:8080/v1/scripts/F62A044393E6BA95C584:1609372800000:990XAcVGoZh01r5Mj5HQOjAtSM
Unable to find image 'rancher/agent:v1.2.11' locally
v1.2.11: Pulling from rancher/agent
b3e1c725a85f: Pull complete 
6a710864a9fc: Pull complete 
d0ac3b234321: Pull complete 
... ...
Digest: sha256:0fba3fb10108f7821596dc5ad4bfa30e93426d034cd3471f6ccd3afb5f87a963
Status: Downloaded newer image for rancher/agent:v1.2.11

INFO: Running Agent Registration Process, CATTLE_URL=http://192.168.56.109:8080/v1
INFO: Attempting to connect to: http://192.168.56.109:8080/v1
INFO: http://192.168.56.109:8080/v1 is accessible
INFO: Configured Host Registration URL info: CATTLE_URL=http://192.168.56.109:8080/v1 ENV_URL=http://192.168.56.109:8080/v1
INFO: Inspecting host capabilities
INFO: Boot2Docker: false
INFO: Host writable: true
INFO: Token: xxxxxxxx
INFO: Running registration
INFO: Printing Environment
INFO: ENV: CATTLE_ACCESS_KEY=DB516EED6E847ED7DDC0
INFO: ENV: CATTLE_HOME=/var/lib/cattle
INFO: ENV: CATTLE_REGISTRATION_ACCESS_KEY=registrationToken
INFO: ENV: CATTLE_REGISTRATION_SECRET_KEY=xxxxxxx
INFO: ENV: CATTLE_SECRET_KEY=xxxxxxx
INFO: ENV: CATTLE_URL=http://192.168.56.109:8080/v1
INFO: ENV: DETECTED_CATTLE_AGENT_IP=172.17.0.1
INFO: ENV: RANCHER_AGENT_IMAGE=rancher/agent:v1.2.11
INFO: Launched Rancher Agent: 9c2effdb3359db3a5d99ebcd7f42c45463c6f78ec8c273223b7c971a72658a05

再次验证,当前所部署的服务,如下所示:

代码语言:javascript复制
[administrator@JavaLangOutOfMemory ~ ]% sudo docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED              STATUS              PORTS                              NAMES
f0e9f2637f43        nginx:latest                      "/.r/r /docker-entry…"   About a minute ago   Up About a minute                                      r-healthcheck-nginx-luga-1-d9af126a
3240cd2c4ccf        rancher/scheduler:v0.8.6          "/.r/r /rancher-entr…"   10 minutes ago       Up 10 minutes                                          r-scheduler-scheduler-1-5f8c681c
a7859b70dac9        rancher/healthcheck:v0.3.8        "/.r/r /rancher-entr…"   10 minutes ago       Up 10 minutes                                          r-healthcheck-healthcheck-1-86952e81
6f261bc3df1e        rancher/dns:v0.17.4               "/rancher-entrypoint…"   14 minutes ago       Up 14 minutes                                          r-network-services-metadata-dns-1-46dc9230
7867f359fec4        rancher/net:v0.13.17              "/rancher-entrypoint…"   15 minutes ago       Up 15 minutes                                          r-ipsec-ipsec-connectivity-check-1-3b4f5a57
f4e2738814b1        rancher/net:v0.13.17              "/rancher-entrypoint…"   15 minutes ago       Up 15 minutes                                          r-ipsec-ipsec-router-1-4d30a19e
e94d9af26779        rancher/metadata:v0.10.4          "/rancher-entrypoint…"   15 minutes ago       Up 15 minutes                                          r-network-services-metadata-1-25991fed
a10d25dd09e9        rancher/net:holder                "/.r/r /rancher-entr…"   15 minutes ago       Up 15 minutes                                          r-ipsec-ipsec-1-1e27ebd3
b4bf0b86ce63        rancher/network-manager:v0.7.22   "/rancher-entrypoint…"   16 minutes ago       Up 15 minutes                                          r-network-services-network-manager-1-55e09939
86a2e86d660b        rancher/net:v0.13.17              "/rancher-entrypoint…"   17 minutes ago       Up 15 minutes                                          r-ipsec-cni-driver-1-ec5b2699
9c2effdb3359        rancher/agent:v1.2.11             "/run.sh run"            18 minutes ago       Up 18 minutes                                          rancher-agent
cd80c8792754        rancher/server                    "/usr/bin/entry /usr…"   About an hour ago    Up About an hour    3306/tcp, 0.0.0.0:8080->8080/tcp   happy_davinci

然后,通过浏览器访问:

此处窗体,主要显示主机资源新增操作,我们以实际场景需求进行添加主机操作,根据系统相关指令进行操作,即,基础架构->保存->生成一条命令,在docker中运行。成功如下所示:

然后添加基础对象及容器服务,我们以Nginx代理服务为例,输入对应的镜像参数、暴露的公网端口及其他可配置选项,具体可参考如下:

此时,进行创建,并验证是否部署成功,通过浏览器访问:

我们再看下当前所运行的容器服务:

从上述场景可以看出,Rancher提供的功能较为丰富,其所创建的应用无论是基于自己开发定制,还是平台自身集成的应用组件,部署起来都较为方便,能够在较短时间内完成,同时可以根据实际情况进行多副本部署、运行、监控、配置以及Web Api查看。

因其功能过于强大,其他功能暂不赘述。我们来看下Rancher所提供的原生的Kubernetes API,对于常用资源处理,通过访问https://rancher_url/v3/可以查看到具体支持的类型。对于类似ServiceAccount之类的资源,可通过 Rancher UI 代理去访问 K8S 直连 API,接口地址为:rancher_url/k8s/clusters/<集群ID>/api/<API版本>/<资源类型>。具体可参考如下,当我们访问以下链接时:https://rancher_url/k8s/clusters/c-nlbtk/api/v1/serviceaccounts/,会返回如下结果:

代码语言:javascript复制
{
  "kind": "ServiceAccountList",
  "apiVersion": "v1",
  "metadata": {
    "selfLink": "/api/v1/serviceaccounts",
    "resourceVersion": "9972577"
  },
  "items": [
    {
      "metadata": {
        "name": "default",
        "namespace": "cattle-logging",
        "selfLink": "/api/v1/namespaces/cattle-logging/serviceaccounts/default",
        "uid": "f570131c-f3eb-4018-8119-85c1544f5750",
        "resourceVersion": "3531475",
        "creationTimestamp": "2021-01-30T10:24:36Z"
      },
      "secrets": [
        {
          "name": "default-token-w6pjb"
        }
      ]
    },

由于Rancher 1.x 最初设计初衷是为了支持多种容器编排引擎而构建的,其中包括自己的容器编排引擎 Cattle。但随着 Kubernetes生态体系在市场上的兴起,Rancher 2.x 已经完全转向了 Kubernetes。Rancher 2.x 可以部署和管理在任何地方运行的 Kubernetes 集群平台中,故其支持K8S所涉及的API。故对我们来说,都是主要基于GO语言,熟悉Rancher 2.x对于学习Kubernetes技术体系还是具有较大帮助。

0 人点赞