k8s学习(二十) helm的基本使用
程序员文章站
2024-03-11 17:02:07
...
1、创建仓库
查看仓库
[[email protected] test]# helm repo list
NAME URL
stable https://kubernetes-charts.storage.googleapis.com
local http://127.0.0.1:8879/charts
谷歌的地址使用不了,将默认的仓库地址改成github的
[[email protected] test]# helm repo remove stable
"stable" has been removed from your repositories
[[email protected] test]# helm repo add stable https://cnych.github.io/kube-charts-mirror/
"stable" has been added to your repositories
[[email protected] test]# helm repo list
NAME URL
local http://127.0.0.1:8879/charts
stable https://cnych.github.io/kube-charts-mirror/
[[email protected] test]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete.
搜索chart
[[email protected] test]# helm search mysql
NAME CHART VERSION APP VERSION DESCRIPTION
stable/mysql 0.10.2 5.7.14 Fast, reliable, scalable, and easy to use open-source rel...
stable/mysqldump 1.0.0 5.7.21 A Helm chart to help backup MySQL databases using mysqldump
stable/prometheus-mysql-exporter 0.2.1 v0.11.0 A Helm chart for prometheus mysql exporter with cloudsqlp...
stable/percona 0.3.3 5.7.17 free, fully compatible, enhanced, open source drop-in rep...
stable/percona-xtradb-cluster 0.5.0 5.7.19 free, fully compatible, enhanced, open source drop-in rep...
stable/phpmyadmin 1.3.0 4.8.3 phpMyAdmin is an mysql administration frontend
stable/gcloud-sqlproxy 0.6.0 1.11 Google Cloud SQL Proxy
stable/mariadb 5.2.3 10.1.37 Fast, reliable, scalable, and easy to use open-source rel...
查看chart的详细信息
helm inspect stable/mysql
2、安装charts
[[email protected] test]# helm install stable/mysql --name mysqldb
NAME: mysqldb
LAST DEPLOYED: Wed Sep 25 13:49:52 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/ConfigMap
NAME DATA AGE
mysqldb-test 1 0s
==> v1/PersistentVolumeClaim
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysqldb Pending 0s Filesystem
==> v1/Secret
NAME TYPE DATA AGE
mysqldb Opaque 2 0s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysqldb ClusterIP 10.110.29.71 <none> 3306/TCP 0s
==> v1beta1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
mysqldb 0/1 0 0 0s
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysqldb.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysqldb -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
To connect to your database:
1. Run an Ubuntu pod that you can use as a client:
kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
2. Install the mysql client:
$ apt-get update && apt-get install mysql-client -y
3. Connect using the mysql cli, then provide your password:
$ mysql -h mysqldb -p
To connect to your database directly from outside the K8s cluster:
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
# Execute the following command to route the connection:
kubectl port-forward svc/mysqldb 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
[[email protected] test]# kubectl get pods
NAME READY STATUS RESTARTS AGE
dns-test 1/1 Running 0 14d
helloworld011-5cf986495c-6zslr 1/1 Running 0 14d
helloworld011-5cf986495c-9xh5d 1/1 Running 0 14d
innocent-boxer-hello-helm-867bd48ccc-k6jmw 1/1 Running 0 14m
kube-hpa-demo-d789d89b-9xgdx 1/1 Running 0 15d
kube-hpa-demo-d789d89b-pw77j 1/1 Running 0 15d
kube-node-6545cf5596-khw4x 1/1 Running 0 15d
kube-node-6545cf5596-q7kd7 1/1 Running 0 15d
liveness-tcpsocket 1/1 Running 0 15d
mysqldb-6ffc996bdb-lxgsp 0/1 Pending 0 36s
nfs-client-provisioner-84f967cff9-dtxxt 1/1 Running 0 8d
nfs-web-0 1/1 Running 0 8d
nfs-web-1 1/1 Running 0 8d
nginx-ds-7spc2 1/1 Running 0 14d
nginx-ds-ffd9v 1/1 Running 0 14d
nginx-ds-rmqvl 1/1 Running 0 5d4h
static-nginx-k8s-node1 1/1 Running 0 15d
use-pvc-deployment-85997f976b-llg9h 1/1 Running 0 9d
use-pvc-deployment-85997f976b-tm92t 1/1 Running 0 9d
web-0 1/1 Running 0 14d
web-1 1/1 Running 0 14d
Helm 并不会一直等到所有资源都运行才退出。因为很多 charts 需要的镜像资源非常大,所以可能需要很长时间才能安装到集群中去。
要跟踪 release 状态或重新读取配置信息,可以使用 helm status 查看:
[[email protected] test]# helm status mysqldb
LAST DEPLOYED: Wed Sep 25 13:49:52 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/ConfigMap
NAME DATA AGE
mysqldb-test 1 2m11s
==> v1/PersistentVolumeClaim
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysqldb Pending 2m11s Filesystem
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
mysqldb-6ffc996bdb-lxgsp 0/1 Pending 0 2m11s
==> v1/Secret
NAME TYPE DATA AGE
mysqldb Opaque 2 2m11s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysqldb ClusterIP 10.110.29.71 <none> 3306/TCP 2m11s
==> v1beta1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
mysqldb 0/1 1 0 2m11s
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
mysqldb.default.svc.cluster.local
To get your root password run:
MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default mysqldb -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)
To connect to your database:
1. Run an Ubuntu pod that you can use as a client:
kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il
2. Install the mysql client:
$ apt-get update && apt-get install mysql-client -y
3. Connect using the mysql cli, then provide your password:
$ mysql -h mysqldb -p
To connect to your database directly from outside the K8s cluster:
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
# Execute the following command to route the connection:
kubectl port-forward svc/mysqldb 3306
mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
3、自定义charts
查看chart的可配属性
[[email protected] test]# helm inspect values stable/rabbitmq
## Global Docker image registry
## Please, note that this will override the image registry for all the images, including dependencies, configured to use the global value
##
# global:
# imageRegistry:
## Bitnami RabbitMQ image version
## ref: https://hub.docker.com/r/bitnami/rabbitmq/tags/
##
image:
registry: docker.io
repository: bitnami/rabbitmq
tag: 3.7.8
## set to true if you would like to see extra information on logs
## it turns BASH and NAMI debugging in minideb
## ref: https://github.com/bitnami/minideb-extras/#turn-on-bash-debugging
debug: false
## Specify a imagePullPolicy
## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent'
## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images
##
pullPolicy: IfNotPresent
## Optionally specify an array of imagePullSecrets.
## Secrets must be manually created in the namespace.
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
##
# pullSecrets:
# - myRegistrKeySecretName
## does your cluster have rbac enabled? assume yes by default
rbacEnabled: true
## section of specific values for rabbitmq
rabbitmq:
## RabbitMQ application username
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
username: user
## RabbitMQ application password
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
# password:
## Erlang cookie to determine whether different nodes are allowed to communicate with each other
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
# erlangCookie:
## Node port
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
# nodePort: 30672
## Amqp port
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
amqpPort: 5672
## Dist port
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
distPort: 25672
## Node name to cluster with. e.g.: `[email protected]`
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
# rabbitmqClusterNodeName:
## RabbitMQ Manager port
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
##
managerPort: 15672
## RabbitMQ Disk free limit
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
## ref: https://www.rabbitmq.com/disk-alarms.html
##
diskFreeLimit: '"6GiB"'
## RabbitMQ Max File Descriptors
## ref: https://github.com/bitnami/bitnami-docker-rabbitmq#environment-variables
## ref: https://www.rabbitmq.com/install-debian.html#kernel-resource-limits
##
ulimitNofiles: '65536'
## Plugins to enable
plugins: |-
[rabbitmq_management, rabbitmq_peer_discovery_k8s].
## Clustering settings
clustering:
address_type: ip
k8s_domain: cluster.local
## Configution file content
configuration: |-
## Clustering
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_k8s
cluster_formation.k8s.host = kubernetes.default.svc.cluster.local
cluster_formation.node_cleanup.interval = 10
cluster_formation.node_cleanup.only_log_warning = true
cluster_partition_handling = autoheal
## queue master locator
queue_master_locator=min-masters
## enable guest user
loopback_users.guest = false
## Kubernetes service type
serviceType: ClusterIP
# Additional pod labels to apply
podLabels: {}
## Pod Security Context
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
##
securityContext:
enabled: true
fsGroup: 1001
runAsUser: 1001
persistence:
## this enables PVC templates that will create one per pod
enabled: false
## rabbitmq data Persistent Volume Storage Class
## If defined, storageClassName: <storageClass>
## If set to "-", storageClassName: "", which disables dynamic provisioning
## If undefined (the default) or set to null, no storageClassName spec is
## set, choosing the default provisioner. (gp2 on AWS, standard on
## GKE, AWS & OpenStack)
##
# storageClass: "-"
accessMode: ReadWriteOnce
# If you change this value, you might have to adjust `rabbitmq.diskFreeLimit` as well.
size: 8Gi
## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources: {}
## Replica count, set to 1 to provide a default available cluster
replicas: 1
## Node labels and tolerations for pod assignment
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector
## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#taints-and-tolerations-beta-feature
nodeSelector: {}
tolerations: []
affinity: {}
## annotations for rabbitmq pods
podAnnotations: {}
## Configure the ingress resource that allows you to access the
## Wordpress installation. Set up the URL
## ref: http://kubernetes.io/docs/user-guide/ingress/
##
ingress:
## Set to true to enable ingress record generation
enabled: false
## The list of hostnames to be covered with this ingress record.
## Most likely this will be just one host, but in the event more hosts are needed, this is an array
## hostName: foo.bar.com
## Set this to true in order to enable TLS on the ingress record
## A side effect of this will be that the backend wordpress service will be connected at port 443
tls: false
## If TLS is set to true, you must declare what secret will store the key/certificate for TLS
tlsSecret: myTlsSecret
## Ingress annotations done as key:value pairs
## If you're using kube-lego, you will want to add:
## kubernetes.io/tls-acme: true
##
## For a full list of possible ingress annotations, please see
## ref: https://github.com/kubernetes/ingress-nginx/blob/master/docs/annotations.md
##
## If tls is set to true, annotation ingress.kubernetes.io/secure-backends: "true" will automatically be set
annotations:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: true
## The following settings are to configure the frequency of the lifeness and readiness probes
livenessProbe:
enabled: true
initialDelaySeconds: 120
timeoutSeconds: 5
periodSeconds: 5
failureThreshold: 6
successThreshold: 1
readinessProbe:
enabled: true
initialDelaySeconds: 10
timeoutSeconds: 3
periodSeconds: 5
failureThreshold: 3
successThreshold: 1
metrics:
enabled: false
image:
registry: docker.io
repository: kbudde/rabbitmq-exporter
tag: v0.29.0
pullPolicy: IfNotPresent
resources: {}
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9090"
建立rabbitmq-test.yaml
修改健康检测的配置
readinessProbe:
initialDelaySeconds: 200
[[email protected] test]# helm install -f rabbitmq-test.yaml stable/rabbitmq --name myrabbitmq
NAME: myrabbitmq
LAST DEPLOYED: Wed Sep 25 14:14:45 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/ConfigMap
NAME DATA AGE
myrabbitmq-config 2 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
myrabbitmq-0 0/1 ContainerCreating 0 0s
==> v1/Role
NAME AGE
myrabbitmq-endpoint-reader 0s
==> v1/RoleBinding
NAME AGE
myrabbitmq-endpoint-reader 0s
==> v1/Secret
NAME TYPE DATA AGE
myrabbitmq Opaque 2 0s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
myrabbitmq ClusterIP 10.103.195.121 <none> 4369/TCP,5672/TCP,25672/TCP,15673/TCP 0s
myrabbitmq-headless ClusterIP None <none> 4369/TCP,5672/TCP,25672/TCP,15673/TCP 0s
==> v1/ServiceAccount
NAME SECRETS AGE
myrabbitmq 1 0s
==> v1beta2/StatefulSet
NAME READY AGE
myrabbitmq 0/1 0s
NOTES:
** Please be patient while the chart is being deployed **
Credentials:
Username : user
echo "Password : $(kubectl get secret --namespace default myrabbitmq -o jsonpath="{.data.rabbitmq-password}" | base64 --decode)"
echo "ErLang Cookie : $(kubectl get secret --namespace default myrabbitmq -o jsonpath="{.data.rabbitmq-erlang-cookie}" | base64 --decode)"
RabbitMQ can be accessed within the cluster on port at myrabbitmq.default.svc.cluster.local
To access for outside the cluster, perform the following steps:
To Access the RabbitMQ AMQP port:
kubectl port-forward --namespace default svc/myrabbitmq 5672:5672
echo "URL : amqp://127.0.0.1:5672/"
To Access the RabbitMQ Management interface:
kubectl port-forward --namespace default svc/myrabbitmq 15673:15673
echo "URL : http://127.0.0.1:15672/"
[[email protected] test]#
查看pod
[[email protected] test]# kubectl get pods
NAME READY STATUS RESTARTS AGE
dns-test 1/1 Running 0 14d
helloworld011-5cf986495c-6zslr 1/1 Running 0 14d
helloworld011-5cf986495c-9xh5d 1/1 Running 0 14d
innocent-boxer-hello-helm-867bd48ccc-k6jmw 1/1 Running 0 55m
kube-hpa-demo-d789d89b-9xgdx 1/1 Running 0 15d
kube-hpa-demo-d789d89b-pw77j 1/1 Running 0 15d
kube-node-6545cf5596-khw4x 1/1 Running 0 15d
kube-node-6545cf5596-q7kd7 1/1 Running 0 15d
liveness-tcpsocket 1/1 Running 0 15d
myrabbitmq-0 0/1 Running 0 46s
mysqldb-6ffc996bdb-lxgsp 0/1 Pending 0 41m
nfs-client-provisioner-84f967cff9-dtxxt 1/1 Running 0 9d
nfs-web-0 1/1 Running 0 8d
nfs-web-1 1/1 Running 0 8d
nginx-ds-7spc2 1/1 Running 0 14d
nginx-ds-ffd9v 1/1 Running 0 14d
nginx-ds-rmqvl 1/1 Running 0 5d5h
static-nginx-k8s-node1 1/1 Running 0 15d
use-pvc-deployment-85997f976b-llg9h 1/1 Running 0 9d
use-pvc-deployment-85997f976b-tm92t 1/1 Running 0 9d
web-0 1/1 Running 0 14d
web-1 1/1 Running 0 14d
发现myrabbitmq-0 的pod 一直是0/1等待3到4分钟变为1/1,因为先从配置文件rabbitmq-test.yaml内修改readiness probe的初始化延时时间为200s
过4分钟后
[[email protected] test]# kubectl get pods
NAME READY STATUS RESTARTS AGE
dns-test 1/1 Running 0 14d
helloworld011-5cf986495c-6zslr 1/1 Running 0 14d
helloworld011-5cf986495c-9xh5d 1/1 Running 0 14d
innocent-boxer-hello-helm-867bd48ccc-k6jmw 1/1 Running 0 59m
kube-hpa-demo-d789d89b-9xgdx 1/1 Running 0 15d
kube-hpa-demo-d789d89b-pw77j 1/1 Running 0 15d
kube-node-6545cf5596-khw4x 1/1 Running 0 15d
kube-node-6545cf5596-q7kd7 1/1 Running 0 15d
liveness-tcpsocket 1/1 Running 0 15d
myrabbitmq-0 1/1 Running 0 4m11s
mysqldb-6ffc996bdb-lxgsp 0/1 Pending 0 45m
nfs-client-provisioner-84f967cff9-dtxxt 1/1 Running 0 9d
nfs-web-0 1/1 Running 0 8d
nfs-web-1 1/1 Running 0 8d
nginx-ds-7spc2 1/1 Running 0 14d
nginx-ds-ffd9v 1/1 Running 0 14d
nginx-ds-rmqvl 1/1 Running 0 5d5h
static-nginx-k8s-node1 1/1 Running 0 15d
use-pvc-deployment-85997f976b-llg9h 1/1 Running 0 9d
use-pvc-deployment-85997f976b-tm92t 1/1 Running 0 9d
web-0 1/1 Running 0 14d
web-1 1/1 Running 0 14d
4、升级charts
命令为:
helm upgrade -f rabbitmq-test.yaml myrabbitmq stable/rabbitmq
查看历史版本
[[email protected] test]# helm history myrabbitmq
REVISION UPDATED STATUS CHART DESCRIPTION
1 Wed Sep 25 14:30:56 2019 DEPLOYED rabbitmq-3.6.3 Install complete
回滚
helm rollback myrabbitmq xxx
xxx为版本号 1、2、3、4、...