安装
可以在https://github.com/helm/helm/releases中找到需要的版本
这里选择helm-v3.1.1-linux-amd64.tar.gz
wget https://get.helm.sh/helm-v3.1.1-linux-amd64.tar.gz
tar zxvf helm-v3.1.1-linux-amd64.tar.gz
cp linux-amd64/helm /usr/local/bin/
然后需要添加需要的仓库,并更新,例如
helm repo add stable https://kubernetes-charts.storage.googleapis.com
helm repo update
测试
root@ubuntu:/opt# helm install nginx-ingress stable/nginx-ingress
NAME: nginx-ingress
LAST DEPLOYED: 2020-03-30 20:31:19.070618474 -0700 PDT m=+2.346730523
NAMESPACE: default
STATUS: deployed
NOTES:
The nginx-ingress controller has been installed.
It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status by running 'kubectl --namespace default get services -o wide -w nginx-ingress-controller'
An example Ingress that makes use of the controller:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: example
namespace: foo
spec:
rules:
- host: www.example.com
http:
paths:
- backend:
serviceName: exampleService
servicePort: 80
path: /
# This section is only required if TLS is to be enabled for the Ingress
tls:
- hosts:
- www.example.com
secretName: example-tls
If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:
apiVersion: v1
kind: Secret
metadata:
name: example-tls
namespace: foo
data:
tls.crt: <base64 encoded cert>
tls.key: <base64 encoded key>
type: kubernetes.io/tls
root@ubuntu:/opt# helm ls
NAME NAMESPACE REVISION UPDATED STATUS CHART
nginx-ingress default 1 2020-03-30 20:31:19.070618474 -0700 PDT deployed nginx-ingress-1.34.3
到此说明helm3已经成功安装
如何利用HTTP的方式调用
下载相关代码,修改配置文件,再编译运行
git clone https://github.com/opskumu/helm-wrapper.git
cd helm-wrapper
mv config-example.yaml config.yaml
cat config.yaml
helmRepos:
- name: stable
url: https://kubernetes-charts.storage.googleapis.com
go build
./helm-wrapper
在router.go中有所有的url path,如下:
func RegisterRouter(router *gin.Engine) {
// helm env
envs := router.Group("/api/envs")
{
envs.GET("", getHelmEnvs)
}
// helm repo
repositories := router.Group("/api/repositories")
{
// helm search repo
repositories.GET("/charts", listRepoCharts)
// helm update
repositories.PUT("", updateRepositories)
}
// helm chart
charts := router.Group("/api/charts")
{
charts.GET("", showChartInfo)
}
// helm release
releases := router.Group("/api/namespaces/:namespace/releases")
{
// helm list releases -> helm list
releases.GET("", listReleases)
// helm get
releases.GET("/:release", showReleaseInfo)
// helm install
releases.POST("/:release", installRelease)
// helm upgrade
releases.PUT("/:release", upgradeRelease)
// helm uninstall
releases.DELETE("/:release", uninstallRelease)
// helm rollback
releases.PUT("/:release/versions/:reversion", rollbackRelease)
// helm status <RELEASE_NAME>
releases.GET("/:release/status", getReleaseStatus)
// helm release history
releases.GET("/:release/histories", listReleaseHistories)
}
}
以创建redis为例
创建release
body里的参数必须要填,不许为空,这里随便填一个占位用
curl -XPOST http://127.0.0.1:8080/api/namespaces/default/releases/redis-my?chart=stable/redis -d'{"name":"my-redis"}' | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 30 100 11 100 19 2 3 0:00:06 0:00:05 0:00:01 2
{
"code": 0
}
查询helm list
root@ubuntu:/opt# curl http://127.0.0.1:8080/api/namespaces/default/releases | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 212 100 212 0 0 3117 0 --:--:-- --:--:-- --:--:-- 3117
{
"code": 0,
"data": [
{
"app_version": "5.0.7",
"chart": "redis",
"chart_version": "10.5.7",
"name": "redis-my",
"namespace": "default",
"revision": "1",
"status": "deployed",
"updated": "2020-03-30 23:18:55.117024429 -0700 PDT"
}
]
}
查看pod列表已经可以看到pod开始创建了
root@ubuntu:/opt# kubectl get pod
NAME READY STATUS RESTARTS AGE
redis-my-master-0 0/1 Pending 0 78s
redis-my-slave-0 0/1 Pending 0 78s
查询helm详情
包含5个参数:"all", “hooks”, “manifest”, “notes”, “values”,分别可查所有和各部分的信息
root@ubuntu:/opt# curl http://127.0.0.1:8080/api/namespaces/default/releases/redis-my?info=all | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15973 0 15973 0 0 229k 0 --:--:-- --:--:-- --:--:-- 229k
{
"code": 0,
"data": {
"info": {
"deleted": "",
"description": "Install complete",
"first_deployed": "2020-03-30T23:18:55.117024429-07:00",
"last_deployed": "2020-03-30T23:18:55.117024429-07:00",
"notes": "...",
"status": "deployed"
},
"manifest": "...",
"name": "redis-my",
"namespace": "default",
"version": 1
}
}
查看helm status
root@ubuntu:/opt# curl http://127.0.0.1:8080/api/namespaces/default/releases/redis-my/status | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3037 0 3037 0 0 27360 0 --:--:-- --:--:-- --:--:-- 27360
{
"code": 0,
"data": {
"app_version": "5.0.7",
"chart": "redis",
"chart_version": "10.5.7",
"name": "redis-my",
"namespace": "default",
"notes": "This Helm chart is deprecated\n\nGiven the `stable` deprecation timeline (https://github.com/helm/charts#deprecation-timeline), the Bitnami maintained Redis Helm chart is now located at bitnami/charts (https://github.com/bitnami/charts/).\n\nThe Bitnami repository is already included in the Hubs and we will continue providing the same cadence of updates, support, etc that we've been keeping here these years. Installation instructions are very similar, just adding the _bitnami_ repo and using it during the installation (`bitnami/<chart>` instead of `stable/<chart>`)\n\n```bash\n$ helm repo add bitnami https://charts.bitnami.com/bitnami\n$ helm install my-release bitnami/<chart> # Helm 3\n$ helm install --name my-release bitnami/<chart> # Helm 2\n```\n\nTo update an exisiting _stable_ deployment with a chart hosted in the bitnami repository you can execute\n ```bash $ helm\n repo add bitnami https://charts.bitnami.com/bitnami\n $ helm upgrade my-release bitnami/<chart>\n ```\n\n Issues and PRs related to the chart itself will be redirected to `bitnami/charts` GitHub repository. In the same way, we'll be happy to answer questions related to this migration process in this issue (https://github.com/helm/charts/issues/20969) created as a common place for discussion.\n\n** Please be patient while the chart is being deployed **\nRedis can be accessed via port 6379 on the following DNS names from within your cluster:\n\nredis-my-master.default.svc.cluster.local for read/write operations\nredis-my-slave.default.svc.cluster.local for read-only operations\n\n\nTo get your password run:\n\n export REDIS_PASSWORD=$(kubectl get secret --namespace default redis-my -o jsonpath=\"{.data.redis-password}\" | base64 --decode)\n\nTo connect to your Redis server:\n\n1. Run a Redis pod that you can use as a client:\n\n kubectl run --namespace default redis-my-client --rm --tty -i --restart='Never' \\\n --env REDIS_PASSWORD=$REDIS_PASSWORD \\\n --image docker.io/bitnami/redis:5.0.7-debian-10-r32 -- bash\n\n2. Connect using the Redis CLI:\n redis-cli -h redis-my-master -a $REDIS_PASSWORD\n redis-cli -h redis-my-slave -a $REDIS_PASSWORD\n\nTo connect to your database from outside the cluster execute the following commands:\n\n kubectl port-forward --namespace default svc/redis-my-master 6379:6379 &\n redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD\n\n\n",
"revision": "1",
"status": "deployed",
"updated": "2020-03-30 23:18:55.117024429 -0700 PDT"
}
}
查看helm history
root@ubuntu:/opt# curl http://127.0.0.1:8080/api/namespaces/default/releases/redis-my/histories | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 181 100 181 0 0 1757 0 --:--:-- --:--:-- --:--:-- 1757
{
"code": 0,
"data": [
{
"app_version": "5.0.7",
"chart": "redis-10.5.7",
"description": "Install complete",
"revision": 1,
"status": "deployed",
"updated": "2020-03-30T23:18:55.117024429-07:00"
}
]
}
删除helm release
root@ubuntu:/opt# curl -XDELETE http://127.0.0.1:8080/api/namespaces/default/releases/redis-my | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11 100 11 0 0 14 0 --:--:-- --:--:-- --:--:-- 14
{
"code": 0
}

501

被折叠的 条评论
为什么被折叠?



