kubernetes集成rancher
4 min read

kubernetes集成rancher

rancher/rancher:latest

导入rancher镜像

[root@k8s-master-01 ~]# docker load < rancher.tar
805802706667: Loading layer [==================================================>]  65.61MB/65.61MB
.
.
.
51690c325aec: Loading layer [==================================================>]  3.584kB/3.584kB
8ba97a0b077c: Loading layer [==================================================>]   1.15MB/1.15MB
Loaded image: rancher/rancher:latest

[root@k8s-master-01 ~]# docker images
REPOSITORY                                                                     TAG                 IMAGE ID            CREATED             SIZE
rancher/rancher                                                                latest              2159e92d1f8d        3 weeks ago         964MB

启动rancher

[root@k8s-master-01 ~]# docker run -d --restart=unless-stopped -p 18080:80 -p 18443:443 --privileged rancher/rancher
[root@k8s-master-01 ~]# docker ps |grep rancher
d147b7a52a68        rancher/rancher:latest   "entrypoint.sh"     About a minute ago   Up About a minute   0.0.0.0:18080->80/tcp, 0.0.0.0:18443->443/tcp   romantic_wing

验证:
直接在浏览器访问:http://192.168.9.27:18080

下载rancher二进制文件

[root@k8s-master-01 ~]# tar xf rancher-linux-amd64-v2.4.6.tar.gz
[root@k8s-master-01 ~]# ll
总用量 4428
-rw-------. 1 root root    1413 11月  2 11:01 anaconda-ks.cfg
-rw-r--r--. 1 root root 4519538 11月  3 20:49 rancher-linux-amd64-v2.4.6.tar.gz
drwxr-xr-x. 2 root root      21 8月  27 04:07 rancher-v2.4.6
[root@k8s-master-01 ~]# cd rancher-v2.4.6/
[root@k8s-master-01 rancher-v2.4.6]# ll
总用量 12736
-rwxr-xr-x. 1 root root 13039846 8月  27 04:07 rancher
[root@k8s-master-01 rancher-v2.4.6]# mv rancher /usr/local/bin/

在浏览器输入一个密码,点击I agree,然后点击continue,一直下一步。

add cluster--->other cluster--->(输入ClusterName)--->执行最下面的那个命令

rancher/rancher-agent:v2.5.1

[root@k8s-master-01 ~]# curl --insecure -sfL https://192.168.9.27:18443/v3/import/p7k4xmz86vkx5kplf889w5jrkhwkc57snhjv8kn6vgcn7dj4n4bb7s.yaml | kubectl apply -f -
clusterrole.rbac.authorization.k8s.io/proxy-clusterrole-kubeapiserver created
clusterrolebinding.rbac.authorization.k8s.io/proxy-role-binding-kubernetes-master created
namespace/cattle-system created
serviceaccount/cattle created
clusterrolebinding.rbac.authorization.k8s.io/cattle-admin-binding created
secret/cattle-credentials-49c2373 created
clusterrole.rbac.authorization.k8s.io/cattle-admin created
deployment.apps/cattle-cluster-agent created


接下来生成一个tooken


进去之后,点击add,然后输入一个名字,然后点击create


接下来就会生成secret和tooken

password:TMZx^HRD
endpiont:https://192.168.9.27:18443/v3
access-key:token-2n9t6
secret-key:b5q52q472twgr42frztqf29qppqv7kdcgrx7lhv5b42dm6xx9ppj7t
tooken:token-2n9t6:b5q52q472twgr42frztqf29qppqv7kdcgrx7lhv5b42dm6xx9ppj7t

接下来在命令行执行命令使rancher和kubernetes结合起来

登录rancher
# rancher login https://prod-rancher.xuetangonline.com:18443/v3  --token token-fdxqq:c2gq98wrg7jp2b9tgzgljcw7ljtslwmkjfp47tsk7qtxptj9625p9j

jenkins调用rancher api发版示例
# rancher kubectl set image deployment/examination-submit-worker examination-submit-worker=guangcai-mirror.xuetangx.info:5000/xuetangx/examination-submit-worker-master-201912128b5a911ed05ec82 -n default

执行详情如下:

[root@k8s-master-01 ~]# rancher login https://192.168.9.27:18443/v3  --token token-2n9t6:b5q52q472twgr42frztqf29qppqv7kdcgrx7lhv5b42dm6xx9ppj7t
The authenticity of server 'https://192.168.9.27:18443' can't be established.
Cert chain is : [Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 9021640734410872581 (0x7d334e7301c11705)
    Signature Algorithm: ECDSA-SHA256
        Issuer: O=dynamiclistener-org,CN=dynamiclistener-ca
        Validity
            Not Before: Nov 3 12:42:14 2020 UTC
            Not After : Nov 3 12:51:48 2021 UTC
        Subject: O=dynamic,CN=dynamic
        Subject Public Key Info:
            Public Key Algorithm: ECDSA
                Public-Key: (256 bit)
                X:
                    91:98:0e:55:8a:8d:e6:b7:c7:f5:04:04:0f:07:40:
                    9a:c4:ae:28:7d:16:aa:e5:5f:fe:56:06:6a:c4:df:
                    47:7b
                Y:
                    d2:45:12:be:f5:f6:95:e6:68:91:64:d4:cd:fe:a0:
                    0d:ea:9e:65:43:4b:ef:78:01:4a:d0:8c:0f:64:30:
                    67:82
                Curve: P-256
        X509v3 extensions:
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
            X509v3 Subject Alternative Name:
                DNS:localhost
                IP Address:127.0.0.1, IP Address:172.16.75.2, IP Address:192.168.9.27

    Signature Algorithm: ECDSA-SHA256
         30:46:02:21:00:88:ba:1b:0c:09:f2:78:65:6c:df:58:b5:03:
         df:df:df:aa:d5:9c:0d:54:f2:01:15:0d:a4:be:e1:e9:e8:5b:
         25:02:21:00:ff:9e:fb:97:86:a7:95:66:7f:47:28:23:34:ef:
         e4:32:e3:83:9f:62:b5:82:8a:92:9f:c6:c3:0f:9a:38:c4:ed
]
Do you want to continue connecting (yes/no)? yes
NUMBER    CLUSTER NAME   PROJECT ID        PROJECT NAME   PROJECT DESCRIPTION
1         fmmu           c-qxk7v:p-q74n8   Default        Default project created for the cluster
2         fmmu           c-qxk7v:p-wxpb4   System         System project created for the cluster
3         local          local:p-2pnvc     System         System project created for the cluster
4         local          local:p-kvwg4     Default        Default project created for the cluster
Select a Project:1
INFO[0029] Saving config to /root/.rancher/cli2.json
京ICP备19055754号