Helm 安装+阿里云镜像配置+memcached部署教程

近期文章:使用 ansible 一键安装kubernetes+containerd+calico集群

前两天通过ansible playbook一键安装了arm架构的kubernetes版本,这两天忙于工作,今天闲下来,安装Helm

Helm安装

根据helm版本支持的kubernetes版本对照表,我是用的是kubernetes 1.25,helm版本不低于3.10才行

https://helm.sh/zh/docs/topics/version_skew/

wget https://get.helm.sh/helm-v3.10.3-linux-arm64.tar.gz
#如果无法下载,可以从华为云下载https://repo.huaweicloud.com/helm/v3.10.3/helm-v3.10.3-linux-arm64.tar.gz
tar zxvf helm-v3.10.3-linux-arm64.tar.gz
mv linux-arm64/helm /usr/bin/
[root@master01 ~]# helm version
version.BuildInfo{Version:"v3.10.3", GitCommit:"835b7334cfe2e5e27870ab3ed4135f136eecc704", GitTreeState:"clean", GoVersion:"go1.18.9"}

配置helm Chat

添加阿里云 chart 仓库

helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
#添加bitnami仓库
helm repo add bitnami https://charts.bitnami.com/bitnami
#查看
[root@master01 ~]# helm repo list
NAME   	URL
aliyun 	https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts
bitnami	https://charts.bitnami.com/bitnami
#更新
[root@master01 ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "aliyun" chart repository
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈

删除 chart 仓库

helm repo remove aliyun

Helm 基本使用

helm 搜索和下载Chart

#搜索
helm search repo aliyun
#下载
helm pull aliyun/memcached
#解压
tar zxvf memcached-2.0.1.tgz
[root@master01 ~]# tree memcached
memcached
├── Chart.yaml #chart 的基本信息,包括版本名字之类
├── README.md
├── templates #存放 k8s 的部署资源模板,通过渲染变量得到部署文件
│   ├── _helpers.tpl
│   ├── NOTES.txt
│   ├── pdb.yaml
│   ├── statefulset.yaml
│   └── svc.yaml
└── values.yaml #存放全局变量,templates 下的文件可以调用

1 directory, 8 files

部署 chart

helm 部署 memcached 服务

1、修改 statefulset.yaml 文件

这个文件有三处需要修改
1、apiVersion值改为app/v1
2、新增selector
3、删除affinity亲和性配置
4、修改values.yaml镜像版本
5、修改pdb.yaml中apiVersion: policy/v1

开始具体修改:

#1、apiVersion值改为app/v1
apiVersion: apps/v1
#2、新增selector 
  selector:
    matchLabels:
        app: {{ template "memcached.fullname" . }}
        chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
        release: "{{ .Release.Name }}"
        heritage: "{{ .Release.Service }}"

新增selector相关内容

3、删除affinity 亲和性配置

删除affinity 亲和性配置

4、修改镜像

由于我使用的aarch64系统,配置文件中默认使用的x86的memcached:1.4.36-alpine镜像包,会造成memcached无法启动,故而采用最新的镜像进行测试(因为最新的是arm刚好支持),如果你使用的系统是x86的,可以不用修改

vim values.yaml

将image: memcached:1.4.36-alpine改成image: memcached:latest

5、修改pdb.yaml中apiVersion值为policy/v1

改完配置后就可以使用helm install安装 memcached了

#helm install
[root@master01 memcached]# helm install memcached ./
NAME: memcached
LAST DEPLOYED: Wed Aug 30 09:10:10 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Memcached can be accessed via port 11211 on the following DNS name from within your cluster:
memcached-memcached.default.svc.cluster.local

If you'd like to test your instance, forward the port locally:

  export POD_NAME=$(kubectl get pods --namespace default -l "app=memcached-memcached" -o jsonpath="{.items[0].metadata.name}")
  kubectl port-forward $POD_NAME 11211

In another tab, attempt to set a key:

  $ echo -e 'set mykey 0 60 5\r\nhello\r' | nc localhost 11211

You should see:

  STORED

#查看 memcache 是否部署成功:
[root@master01 memcached]# kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
memcached-memcached-0   1/1     Running   0          2m4s
memcached-memcached-1   1/1     Running   0          91s
memcached-memcached-2   1/1     Running   0          47s

测试 memecached 服务是否正常

#安装nc
yum install -y nc
export POD_NAME=$(kubectl get pods --namespace default -l "app=memcached-memcached" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 11211

#新开一个终端
echo -e 'set mykey 0 60 5\r\nhello\r' | nc localhost 11211

release 相关操作

#查看 release 发布状态
[root@master01 templates]# helm list
NAME     	NAMESPACE	REVISION	UPDATED                                	STATUS  	CHART          	APP VERSION
memcached	default  	1       	2023-08-30 14:29:44.596707861 +0800 CST	deployed	memcached-2.0.1
#删除 release
[root@master01 templates]# helm delete memcached
release "memcached" uninstalled
#删除 release 会把 release 下对应的资源全部删除
[root@master01 templates]# kubectl get pods
No resources found in default namespace.

部署memcached遇到无法启动

ctr -n=k8s.io images ls|grep memcached
查看镜像,发现docker.io/library/memcached:1.4.36-alpine是x86架构的
尝试拉取最新的memcached,反而是arm64,刚好可以部署
最后删除crictl rmi docker.io/library/memcached:1.4.36-alpine,修改values.yaml镜像即可

Comments

No comments yet. Why don’t you start the discussion?

发表评论