helm使用
helm
0. helm安装
基本上到github上面,下载二进制就行。mac的话用brew安装。
https://github.com/helm/helm
brew:
brew install kubernetes-helm
1. helm基本操作
helm create xx 创建一个chart
helm install chartxx 安装
helm uninstall chartxx 卸载
helm upgrade chartxx 更新
helm template 渲染
helm list 列出已经deploy的应用
v3版本以后使用很方便,不需要repo的操作了,kubeconfig 有了就能用。需要注意先指定kubeconfig的环境变量。或者放到~/.kube/config。
2. helm init (v3已经不需要了)
helm init --upgrade --tiller-image registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.9.1 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
将tiller的版本换了。kube-system应该会有tiller-deploy的deployment,启动就ok。
# kubectl get deployments.apps -n kube-system
NAME READY UP-TO-DATE AVAILABLE AGE
calico-kube-controllers 1/1 1 1 6d8h
coredns 2/2 2 2 6d8h
tiller-deploy 1/1 1 1 2d19h
添加serviceaccount,clusterrolebinding:
kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
卸载helm :
helm reset
3. chart 包制作
helm create
#helm create qymapp
#ls qymapp
charts Chart.yaml templates values.yaml
修改相应文件,打包chart
4. chart 使用
helm install --dry-run --debug <chart_dir> --name <release_name>
# helm install --debug local/qymapp --name qym-test
[debug] Created tunnel using local port: '42233'
[debug] SERVER: "127.0.0.1:42233"
[debug] Original chart version: ""
[debug] Fetched local/qymapp to /root/.helm/cache/archive/qymapp-0.1.0.tgz
[debug] CHART PATH: /root/.helm/cache/archive/qymapp-0.1.0.tgz
NAME: qym-test
REVISION: 1
RELEASED: Wed Oct 23 16:54:34 2019
CHART: qymapp-0.1.0
USER-SUPPLIED VALUES:
{}
COMPUTED VALUES:
affinity: {}
fullnameOverride: ""
image:
pullPolicy: IfNotPresent
repository: nginx
tag: stable
imagePullSecrets: []
ingress:
annotations: {}
enabled: false
hosts:
- host: chart-example.local
paths: []
tls: []
nameOverride: ""
nodeSelector: {}
podSecurityContext: {}
replicaCount: 1
resources: {}
securityContext: {}
service:
port: 80
type: ClusterIP
serviceAccount:
create: true
name: null
tolerations: []
HOOKS:
---
# qym-test-qymapp-test-connection
apiVersion: v1
kind: Pod
metadata:
name: "qym-test-qymapp-test-connection"
labels:
app.kubernetes.io/name: qymapp
helm.sh/chart: qymapp-0.1.0
app.kubernetes.io/instance: qym-test
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Tiller
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['qym-test-qymapp:80']
restartPolicy: Never
MANIFEST:
---
# Source: qymapp/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: qym-test-qymapp
labels:
app.kubernetes.io/name: qymapp
helm.sh/chart: qymapp-0.1.0
app.kubernetes.io/instance: qym-test
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Tiller
---
# Source: qymapp/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: qym-test-qymapp
labels:
app.kubernetes.io/name: qymapp
helm.sh/chart: qymapp-0.1.0
app.kubernetes.io/instance: qym-test
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Tiller
spec:
type: ClusterIP
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: qymapp
app.kubernetes.io/instance: qym-test
---
# Source: qymapp/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: qym-test-qymapp
labels:
app.kubernetes.io/name: qymapp
helm.sh/chart: qymapp-0.1.0
app.kubernetes.io/instance: qym-test
app.kubernetes.io/version: "1.0"
app.kubernetes.io/managed-by: Tiller
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: qymapp
app.kubernetes.io/instance: qym-test
template:
metadata:
labels:
app.kubernetes.io/name: qymapp
app.kubernetes.io/instance: qym-test
spec:
serviceAccountName: qym-test-qymapp
securityContext:
{}
containers:
- name: qymapp
securityContext:
{}
image: "nginx:stable"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{}
LAST DEPLOYED: Wed Oct 23 16:54:34 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
qym-test-qymapp 0/1 1 0 0s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
qym-test-qymapp-5d4bcc5db7-xdrh5 0/1 ContainerCreating 0 0s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
qym-test-qymapp ClusterIP 10.108.218.211 <none> 80/TCP 0s
==> v1/ServiceAccount
NAME SECRETS AGE
qym-test-qymapp 1 0s
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=qymapp,app.kubernetes.io/instance=qym-test" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
# helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
qym-test 1 Wed Oct 23 16:54:34 2019 DEPLOYED qymapp-0.1.0 1.0 default
升级chart包,修改一下
# helm package qymapp
Successfully packaged chart and saved it to: /root/.helm/repository/local/qymapp-0.2.0.tgz
# ls
index.yaml qymapp qymapp-0.1.0.tgz qymapp-0.2.0.tgz
# helm search qymapp -l
NAME CHART VERSION APP VERSION DESCRIPTION
local/qymapp 0.2.0 1.0 A Helm chart for Kubernetes
local/qymapp 0.1.0 1.0 A Helm chart for Kubernetes
helm upgrade qym-test local/qymapp
Release "qym-test" has been upgraded.
LAST DEPLOYED: Wed Oct 23 17:17:13 2019
NAMESPACE: default
STATUS: DEPLOYED
# helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
qym-test 2 Wed Oct 23 17:17:13 2019 DEPLOYED qymapp-0.2.0 1.0 default
v3 不需要package ,直接helm upgrade就行了。是不是很方便。再也回不去了。
参考:
https://helm.sh/
官方文档很不错,重要的几个点都讲了。
这篇文章还缺怎么制作chart包,未完待续。