Helm2的问题
Helm2的一个主要问题是需要在k8s集群里面运行一个服务端,而这就需要把tiller的端口暴露给外界,会产生安全隐患。
在helm 2中引入的tiller主要是当时k8s还没有RBAC机制,所以就引入了服务端tiller。
而后来k8s的功能相应完善,加入了RBAC和CRD等,都使得tiller这个东西显得多余。
helm3只有一个客户端,没有服务端,所以安装起来很方便,把相应的程序下下来即可,不需要helm init安装了。
helm3的特性
相对于helm2,helm3有几大特性:
移除了tiller
支持分布式helm hub, 有了它就可以在很多时候不需要手动添加非官方repo了,例如helm3 search hub
为chart输入值进行json schema验证。
可以给helm charts添加test了,通过helm test 就能针对部署的应用跑一些tests。
部署的时候release name必须指定了,helm2的时候不指定会自动生成一个。
删除的时候不需要–purge了,删了就是删了。
地址: https://get.helm.sh/helm-v3.2.3-linux-amd64.tar.gz
[root@master k8s]# tar xf helm-v3.2.3-linux-amd64.tar.gz
[root@master k8s]# cd linux-amd64/
[root@master linux-amd64]# ls
helm LICENSE README.md
[root@master linux-amd64]# cp helm /usr/local/bin/
[root@master linux-amd64]# cd
[root@master ~]# helm version
version.BuildInfo{Version:"v3.2.3", GitCommit:"8f832046e258e2cb800894579b1b3b50c2d83492", GitTreeState:"clean", GoVersion:"go1.13.12"}
$ helm repo add stable https://apphub.aliyuncs.com/stable
查看仓库:
[root@master conf]# helm repo list
NAME URL
stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm2中的 helm inspect 已经被helm show 取代 helm3命令,根据 helm --help
查看
查搜索redis chart
[root@master conf]# helm search repo redis
NAME CHART VERSION APP VERSION DESCRIPTION
stable/redis 1.1.15 4.0.8 Open source, advanced key-value store. It is of...
stable/redis-ha 2.0.1 Highly available Redis cluster with multiple se...
stable/sensu 0.2.0
redis-ha 为redis集群模式
可以用helm show readme stable/redis
查看安装说明
以下表格列出了Redis chart的配置参数及其默认值。
Parameter | Description | Default |
---|---|---|
image |
Redis image | bitnami/redis:{VERSION} |
imagePullPolicy |
Image pull policy | IfNotPresent |
serviceType |
Kubernetes Service type | ClusterIP |
usePassword |
Use password | true |
redisPassword |
Redis password | Randomly generated |
args |
Redis command-line args | [] |
redisExtraFlags |
Redis additional command line flags | [] |
persistence.enabled |
Use a PVC to persist data | true |
persistence.path |
Path to mount the volume at, to use other images | /bitnami |
persistence.subPath |
Subdirectory of the volume to mount at | "" |
persistence.existingClaim |
Use an existing PVC to persist data | nil |
persistence.storageClass |
Storage class of backing PVC | generic |
persistence.accessMode |
Use volume as ReadOnly or ReadWrite | ReadWriteOnce |
persistence.size |
Size of data volume | 8Gi |
resources |
CPU/Memory resource requests/limits | Memory: 256Mi , CPU: 100m |
metrics.enabled |
Start a side-car prometheus exporter | false |
metrics.image |
Exporter image | oliver006/redis_exporter |
metrics.imageTag |
Exporter image | v0.11 |
metrics.imagePullPolicy |
Exporter image pull policy | IfNotPresent |
metrics.resources |
Exporter resource requests/limit | Memory: 256Mi , CPU: 100m |
nodeSelector |
Node labels for pod assignment | {} |
tolerations |
Toleration labels for pod assignment | [] |
networkPolicy.enabled |
Enable NetworkPolicy | false |
networkPolicy.allowExternal |
Don’t require client label for connections | true |
service.annotations |
annotations for redis service | {} |
service.loadBalancerIP |
loadBalancerIP if service type is LoadBalancer |
`` |
securityContext.enabled |
Enable security context | true |
使用‘–set key=value[,key=value] '为 ’ helm install ’ 指定参数 ,例如:
$ helm install --name my-release \
--set redisPassword=secretpassword \
stable/redis
以上命令设置了redis 服务的密码为“secretpassword ”
另外,可以在安装chart时提供了另一种指定参数的形式,YAML文件。例如
$ helm install --name my-release -f values.yaml stable/redis
默认情况下,chart在本地挂载一个持久卷卷,前提是本地必须提前创建好PV。volumes是通过动态PV发放创建的。如果一个pvc已经存在,可以安装期间指定它。
$ helm install --set persistence.existingClaim=PVC_NAME redis
可以先拉取到本地,解压后修改values.yaml文件,然后安装
helm pull aliyuncs/redis
helm install [redis-name] ./redis -n [namespace]
[root@master conf]# helm install redis stable/redis
NAME: redis
LAST DEPLOYED: Fri Apr 16 17:36:12 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Redis can be accessed via port 6379 on the following DNS name from within your cluster:
redis-redis.default.svc.cluster.local
To get your password run:
REDIS_PASSWORD=$(kubectl get secret --namespace default redis-redis -o jsonpath="{.data.redis-password}" | base64 --decode)
To connect to your Redis server:
1. Run a Redis pod that you can use as a client:
kubectl run --namespace default redis-redis-client --rm --tty -i \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image bitnami/redis:4.0.8-r2 -- bash
2. Connect using the Redis CLI:
redis-cli -h redis-redis -a $REDIS_PASSWORD
–name 可以指定name,如未指定,默认为redis
查看安装状态
[root@master conf]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
redis default 1 2021-04-16 16:39:05.0033357 +0800 CST deployed redis-1.1.15 4.0.8
此时查看pod 状态处于pending 状态
[root@master conf]# kubectl get pod
NAME READY STATUS RESTARTS AGE
redis-redis-b69965b4d-466d7 0/1 Pending 0 53s
kubectl describe pod redis-redis-b69965b4d-466d7 可以看到 “pod has unbound immediate PersistentVolumeClaims (repeated 2 times)”
[root@master k8s]# cat redis-pv.yaml
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv-volume
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
目录授权:
chmod 777 -R /mnt/data
再次查看pod 已经正常
helm delete redis