使用helm在k8s集群部署rancher

木木2年前技术文章772

使用helm在k8s集群部署rancher

由于我们的k8s版本是1.22,所以我们直接安装latest版本的rancher。不同版本的rancher helm仓库可以看下面链接

https://docs.rancher.cn/docs/rancher2.5/installation/resources/choosing-version/_index

添加helm仓库

```Plain Text helm repo add rancher-latest https://releases.rancher.com/server-charts/latest helm repo add rancher-alpha https://releases.rancher.com/server-charts/alpha

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111300908821.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111300908821.png)

# 为rancher创建namespace

Plain Text kubectl create namespace cattle-system

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111251744334.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111251744334.png)

# 安装cert-manager

由于我们选择使用自签名的证书来配置rancher,所以需要安装cert-manager来管理这些证书。

## 静默安装

先从github下载对应的yaml文件

[https://github.com/jetstack/cert-manager/releases](https://github.com/jetstack/cert-manager/releases)

Plain Text wget https://github.com/jetstack/cert-manager/releases/download/v1.6.1/cert-manager.crds.yaml

运行该yaml文件即可实现静默安装

## helm安装

## 添加jetstack helm存储库

Plain Text helm repo add jetstack https://charts.jetstack.io

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111251757316.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111251757316.png)

## 更新本地helm存储库缓存

Plain Text helm repo update

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111251758350.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111251758350.png)

## 安装cert-manager

Plain Text helm install \  cert-manager jetstack/cert-manager \  --namespace cert-manager \  --create-namespace \  --version v1.6.1 \  --set installCRDs=true  # 这里我们选择将CRD作为helm的一部分进行安装,所以需要加上 --set installCRDs=true

## 查看cert-manmger状态

Plain Text kubectl get pods --namespace cert-manager

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111300858741.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111300858741.png)

# 安装rancher

查看helm仓库啊中的rancher版本

Plain Text helm search repo --versions

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111300910492.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/202111300910492.png)

可以看到最新版本为2.6.2

Plain Text

这里安装会失败,应为2.6.2的rancher不支持1.22的kubernetes,之后使用了2.6.3版本的rancher安装成功

helm install rancher rancher-latest/rancher \  --namespace cattle-system \  --version 2.6.2 \  --set hostname=rancher.ilomumu.xyz \  --set replicas=1

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211203120004.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211203120004.png)

# ingress-nginx

此时我们的rancher还不能正常访问,这是由于我们还没有安装ingress-nginx(ingress控制器)。先查看下ingress资源

Plain Text kubectl -n cattle-system get ingress

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211203115637.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211203115637.png)

## 安装ingress-nginx

相关文档地址

[https://kubernetes.github.io/ingress-nginx/deploy/](https://kubernetes.github.io/ingress-nginx/deploy/)

helm安装命令

Plain Text helm upgrade --install ingress-nginx ingress-nginx \  --repo https://kubernetes.github.io/ingress-nginx \  --namespace ingress-nginx --create-namespace

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211214135636.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211214135636.png)

安装完成

# 修改rancher的ingress配置

我们要修改rancher的ingress配置将其绑定到我们安装的ingress上

Plain Text kubectl get ingress -n cattle-system

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211214135915.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211214135915.png)

编辑ingress

Plain Text kubectl edit ingress -n cattle-system rancher

原始内容如下

YAML

Please edit the object below. Lines beginning with a '#' will be ignored,

and an empty file will abort the edit. If an error occurs while saving this file will be

reopened with the relevant failures.

# apiVersion: networking.k8s.io/v1 kind: Ingress metadata:  annotations:    cert-manager.io/issuer: rancher    cert-manager.io/issuer-kind: Issuer    meta.helm.sh/release-name: rancher    meta.helm.sh/release-namespace: cattle-system    nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"  creationTimestamp: "2021-12-14T03:46:23Z"  generation: 1  labels:    app: rancher    app.kubernetes.io/managed-by: Helm    chart: rancher-2.6.3-rc2    heritage: Helm    release: rancher  name: rancher  namespace: cattle-system  resourceVersion: "8072"  uid: f98350de-579c-4be0-a82e-08bcbf69fff5 spec:  rules:

  • host: rancher.ilomumu.xyz http:  paths:

    • backend:  service:    name: rancher    port:      number: 80 pathType: ImplementationSpecific tls:

  • hosts:

    • rancher.ilomumu.xyz secretName: tls-rancher-ingress status: loadBalancer: {}

编辑后内容如下

YAML

Please edit the object below. Lines beginning with a '#' will be ignored,

and an empty file will abort the edit. If an error occurs while saving this file will be

reopened with the relevant failures.

# apiVersion: networking.k8s.io/v1 kind: Ingress metadata:  annotations:    cert-manager.io/issuer: rancher    cert-manager.io/issuer-kind: Issuer    meta.helm.sh/release-name: rancher    meta.helm.sh/release-namespace: cattle-system    nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"    nginx.ingress.kubernetes.io/proxy-read-timeout: "1800"    nginx.ingress.kubernetes.io/proxy-send-timeout: "1800"    kubernetes.io/ingress.class: "nginx"   # 添加绑定  creationTimestamp: "2021-12-14T03:46:23Z"  generation: 1  labels:    app: rancher    app.kubernetes.io/managed-by: Helm    chart: rancher-2.6.3-rc2    heritage: Helm    release: rancher  name: rancher  namespace: cattle-system  resourceVersion: "8072"  uid: f98350de-579c-4be0-a82e-08bcbf69fff5 spec:  rules:

  • host: rancher.ilomumu.xyz http:  paths:

    • backend:  service:    name: rancher    port:      number: 80 pathType: ImplementationSpecific tls:

  • hosts:

    • rancher.ilomumu.xyz secretName: tls-rancher-ingress status: loadBalancer: {}

# 修改hosts文件

查看ingress-nginx-control所在节点ip

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215163911.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215163911.png)

修改hosts文件

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215164031.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215164031.png)

# 查看访问端口

Plain Text kubectl get svc -n ingress-nginx

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211214141508.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211214141508.png)

# 进行访问测试

访问地址

Plain Text  https://rancher.ilomumu.xyz:30733

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165639.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165639.png)

# 配置rancher

## 获取bootstrapPassword密码

Plain Text kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{"\n"}}'

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165505.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165505.png)

## 设置密码并同意协议

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165740.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165740.png)

## 设置中文

![https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165903.png](https://teamo-md.oss-cn-shanghai.aliyuncs.com/img/20211215165903.png)

# 完全卸载rancher

rancher官方提供了卸载k8s集群内rancher的工具

[https://github.com/rancher/system-tools](https://github.com/rancher/system-tools)

直接下载该工具使用即可

Plain Text

使用-c 参数指定kubeconfig文件

system-tools remove -c .kube/config ```


相关文章

Go 错误处理与单元测试

1、错误处理1.1 如何定义错误在 Go 语言中,无论是在类型检查还是编译过程中,都是将错误看做值来对待,和 string 或者 integer 这些类型值并不差别。声明一个 string 类型变量和...

通过SDK上传oss文件报错“413 Request Entity Too Large”

通过SDK上传oss文件报错“413 Request Entity Too Large”

问题描述通过SDK上传oss文件返回错误如下,客户反馈上传的文件不大,只有200M。浏览器端访问返回504 timeout报错,同客户核实是每次到1min 30s时候上传大文件会报错com.aliyu...

xx客户大数据相关问题答疑

xx客户大数据相关问题答疑

1、官方发布的补丁是否可以在CDH5.X上patch?如果是cdh的包,需要在cdh官方给出相关补丁包,然后我们可以进行补丁操作。如果是开源的包,是无法进行补丁操作的,因为cdh会对开源有些细节点的适...

在kubernetes中,让某个node成为专属节点

如何让node 去”选择”只有谁(pod)能部署到自身上面?看了下现有的Node Selectors、Node Affinity、Node Taints, 经过比对,发现Node Taints 更适合...

Ingress-Nginx 简介

Ingress-Nginx 简介

Ingress-Nginx github 地址:https://github.com/kubernetes/ingress-nginxIngress-Nginx 官方网站:https://kubern...

切换不同的网络访问同一个业务报错"network error"

切换不同的网络访问同一个业务报错"network error"

问题现象:业务:xxx,使用谷歌浏览器登陆之后,访问“商品档案”模块,会提示“network error”报错内容,但是切换到其他浏览器测试是可以正常访问的,同时,在使用谷歌浏览器访问的情况下,如果切...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。