您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
no available release name found问题排查
发布时间:2023-01-17 16:04:31编辑:雪饮阅读()
Step1
基于上篇出现的错误
[root@k8s-master01 test]# helm install .
Error: no available release name found
首先主yaml文件名称必须是Chart.yaml(首字母必须大写)
[root@k8s-master01 test]# cat Chart.yaml
name: hello-world
version: 1.0.0
这里原本把l写成1了。。。
templates/deployment.yaml
[root@k8s-master01 test]# cat templates/deployment.yaml
apiversion: extensions/v1beta1
kind: Deployment
metadata:
name: hello-world
spec:
replicas: 1
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: hub.atguigu.com/library/myapp:v1
ports:
- containerPort: 80
protocol: TCP
templates/service.yaml还是保持一样
[root@k8s-master01 test]# cat templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: hello-world
Step2
Helm初始化过程中的重点关注地方
[root@k8s-master01 helm]# helm init --service-account tiller --skip-refresh
Creating /root/.helm
Creating /root/.helm/repository
Creating /root/.helm/repository/cache
Creating /root/.helm/repository/local
Creating /root/.helm/plugins
Creating /root/.helm/starters
Creating /root/.helm/cache/archive
Creating /root/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /root/.helm.
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
Happy Helming!
Step3
种种问题我认为是helm有了新版本,这里原本使用的是helm2.13,最新helm某个issue关于helm2迁移到helm3的说明中好像是关于对应的repo仓库位置迁移了,并且新的仓库里面并不包含符合上面Chart.yaml中的hello-world项目的要求的chart。
所以决定升级到helm3
根据当前k8s的版本
[root@k8s-master01 test]# kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.1", GitCommit:"4485c6f18cee9a5d3c3b4e523bd27972b1b53892", GitTreeState:"clean", BuildDate:"2019-07-18T09:18:22Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.1", GitCommit:"4485c6f18cee9a5d3c3b4e523bd27972b1b53892", GitTreeState:"clean", BuildDate:"2019-07-18T09:09:21Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
Step4
安装helm3
wget https://get.helm.sh/helm-v3.3.4-linux-amd64.tar.gz
保留原heml2备用
mv /usr/local/bin/helm /usr/local/bin/helmv2
安装helm3
tar -zxvf helm-v3.3.4-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
chmod a+x /usr/local/bin/helm
查看helm版本
[root@k8s-master01 test]# helm version
version.BuildInfo{Version:"v3.3.4", GitCommit:"a61ce5633af99708171414353ed49547cf05013d", GitTreeState:"clean", GoVersion:"go1.14.9"}
清理
[root@k8s-master01 test]# rm -rf helm-v3.3.4-linux-amd64.tar.gz
[root@k8s-master01 test]# rm -rf linux-amd64
Step5
创建项目
[root@k8s-master01 helm]# helm create hello-world
Creating hello-world
安装项目
[root@k8s-master01 helm]# helm install hello-world ./hello-world
NAME: hello-world
LAST DEPLOYED: Tue Jan 17 11:40:49 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hello-world,app.kubernetes.io/instance=hello-world" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:80
项目结构(应该在创建项目后就已经有了,不安装项目应该就有,手急直接安装了)
[root@k8s-master01 helm]# ls hello-world/
charts Chart.yaml templates values.yaml
· charts/:这个文件夹放的是charts的一些依赖,比如当前的chart依赖于别的chart,那么别的chart就可以安装在这里面,默认为空。
· templates/:文件夹用来存放模版。
· Chart.yaml:当前hello-world chart相关的信息,比如name, version,dependencies等
· values.yaml:templates模块需要被替换的真实的值,这里一般存放的是默认值,可以被重写掉的。
· .helmignore:类似.gitignore
然后可以查看到这个安装好的项目
[root@k8s-master01 helm]# helm list --all
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
hello-world default 1 2023-01-17 11:40:49.902805099 +0800 CST deployed hello-world-0.1.0 1.16.0
然后查看pod在节点2并且可以访问
[root@k8s-master01 helm]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
deployment1-7d967c7ff5-hqblz 1/1 Running 1 20h 10.224.0.38 k8s-master01 <none> <none>
deployment1-7d967c7ff5-k257k 1/1 Running 1 20h 10.224.0.41 k8s-master01 <none> <none>
deployment2-659cdb8b84-4w7pl 1/1 Running 1 20h 10.224.0.39 k8s-master01 <none> <none>
deployment2-659cdb8b84-6k4tt 1/1 Running 2 18d 10.224.0.36 k8s-master01 <none> <none>
hello-world-9fd7c9ff7-jhzdv 1/1 Running 0 10m 10.224.2.27 k8s-node02 <none> <none>
[root@k8s-master01 helm]#
[root@k8s-master01 helm]# curl -i 10.224.2.27
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Tue, 17 Jan 2023 03:51:40 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 23 Apr 2019 10:18:21 GMT
Connection: keep-alive
ETag: "5cbee66d-264"
Accept-Ranges: bytes
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
那么它拉取的镜像是动态配置的
[root@k8s-master01 helm]# cat hello-world/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "hello-world.fullname" . }}
labels:
{{- include "hello-world.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "hello-world.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "hello-world.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "hello-world.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
然后卸载helm3创建的release
[root@k8s-master01 helm]# helm uninstall hello-world
release "hello-world" uninstalled
[root@k8s-master01 helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
将deployment中的镜像修改为本地harbor的镜像
[root@k8s-master01 helm]# cat hello-world/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "hello-world.fullname" . }}
labels:
{{- include "hello-world.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "hello-world.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "hello-world.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "hello-world.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "hub.atguigu.com/library/myapp:v1"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
启动本地harbor服务器再次安装hello-world项目
[root@k8s-master01 helm]# helm install hello-world ./hello-world
NAME: hello-world
LAST DEPLOYED: Tue Jan 17 13:40:47 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hello-world,app.kubernetes.io/instance=hello-world" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:80
然后也能访问
[root@k8s-master01 helm]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
deployment1-7d967c7ff5-hqblz 1/1 Running 1 21h 10.224.0.38 k8s-master01 <none> <none>
deployment1-7d967c7ff5-k257k 1/1 Running 1 21h 10.224.0.41 k8s-master01 <none> <none>
deployment2-659cdb8b84-4w7pl 1/1 Running 1 21h 10.224.0.39 k8s-master01 <none> <none>
deployment2-659cdb8b84-6k4tt 1/1 Running 2 19d 10.224.0.36 k8s-master01 <none> <none>
hello-world-568558dfd6-gzsjg 1/1 Running 0 77s 10.224.2.28 k8s-node02 <none> <none>
[root@k8s-master01 helm]#
[root@k8s-master01 helm]# curl -i 10.224.2.28
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Tue, 17 Jan 2023 05:43:27 GMT
Content-Type: text/html
Content-Length: 65
Last-Modified: Fri, 02 Mar 2018 03:39:12 GMT
Connection: keep-alive
ETag: "5a98c760-41"
Accept-Ranges: bytes
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
其实按照老师原来的规划,这里镜像hub.atguigu.com/library/myapp:v1
是在本地早已经不存在了,但我的另外一个k8s集群中harbor上面是有的。。
这里由于所在地不在原来的k8s集群,所以这里是能用的。
所以这里可以直接使用一个不存在的如
hub.atguigu.com/library/myapp:v2
然后再次卸载再重装后就和老师当时的一样了ImagePullBackOff了
[root@k8s-master01 helm]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
deployment1-7d967c7ff5-hqblz 1/1 Running 1 22h 10.224.0.38 k8s-master01 <none> <none>
deployment1-7d967c7ff5-k257k 1/1 Running 1 22h 10.224.0.41 k8s-master01 <none> <none>
deployment2-659cdb8b84-4w7pl 1/1 Running 1 22h 10.224.0.39 k8s-master01 <none> <none>
deployment2-659cdb8b84-6k4tt 1/1 Running 2 19d 10.224.0.36 k8s-master01 <none> <none>
hello-world-7655ff7c95-7wgcr 0/1 ImagePullBackOff 0 9s 10.224.2.29 k8s-node02 <none> <none>
从流程上面讲,和老师的流程有点逆向了。。。
Step6
重新改回老师最后用的ok的静态镜像路径
wangyanglinux/myapp:v1
其实原本老师这里是演示upgrade的
所以从hub.atguigu.com/library/myapp:v1更换为wangyanglinux/myapp:v1
之间在helm3中操作如
[root@k8s-master01 helm]# helm upgrade hello-world ./hello-world
Release "hello-world" has been upgraded. Happy Helming!
NAME: hello-world
LAST DEPLOYED: Tue Jan 17 14:07:00 2023
NAMESPACE: default
STATUS: deployed
REVISION: 2
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hello-world,app.kubernetes.io/instance=hello-world" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:80
upgrade第一个参数为release名称,第二个参数为chart名称,这里使用目录安装就是对应目录。
升级前后对比我的思路是利用pod,升级前
[root@k8s-master01 helm]# kubectl get deployment -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment1 2/2 2 2 19d nginx wangyanglinux/myapp:v1 name=nginx
deployment2 2/2 2 2 19d nginx2 wangyanglinux/myapp:v2 name=nginx2
hello-world 1/1 1 1 2m49s hello-world hub.atguigu.com/library/myapp:v1 app.kubernetes.io/instance=hello-world,app.kubernetes.io/name=hello-world
升级后
[root@k8s-master01 helm]# kubectl get deployment -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment1 2/2 2 2 19d nginx wangyanglinux/myapp:v1 name=nginx
deployment2 2/2 2 2 19d nginx2 wangyanglinux/myapp:v2 name=nginx2
hello-world 1/1 1 1 3m47s hello-world wangyanglinux/myapp:v1 app.kubernetes.io/instance=hello-world,app.kubernetes.io/name=hello-world
老师当时升级时候release名称为nobby-eel我的理解是不同的地方在于其安装时候没有指定release名称,后面直接跟上文件夹路径“.”
应是自动生成的release名称,在helm list中第一个字段name对应可查看到。
helm3安装时候可能是没有这种方式吧。
这里时候helm3安装时
helm install hello-world ./hello-world
这里hello-world应是realse的名称
Step7
查看helm的项目历史也可以使用了
[root@k8s-master01 helm]# helm history hello-world
REVISION UPDATED STATUS CHART APP VERSION DESCRIPTION
1 Tue Jan 17 14:03:20 2023 superseded hello-world-0.1.0 1.16.0 Install complete
2 Tue Jan 17 14:07:00 2023 deployed hello-world-0.1.0 1.16.0 Upgrade complete
Helm的项目状态也可以使用了
[root@k8s-master01 helm]# helm status hello-world
NAME: hello-world
LAST DEPLOYED: Tue Jan 17 14:07:00 2023
NAMESPACE: default
STATUS: deployed
REVISION: 2
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hello-world,app.kubernetes.io/instance=hello-world" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:80
可以看到helm3的项目状态关于明细的就很少了
如果想要知道项目的访问ip(地址),还得手动查看svc
[root@k8s-master01 helm]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-world ClusterIP 10.101.235.85 <none> 80/TCP 15m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 20d
svc-1 ClusterIP 10.105.127.237 <none> 80/TCP 19d
svc-2 ClusterIP 10.104.19.243 <none> 80/TCP 19d
发现这里的svc并没有绑定外部端口,只有集群内部是80端口。
因为helm3这个hello-world的svc模板中默认svc类型不是NodePort是动态配置的
[root@k8s-master01 helm]# cat hello-world/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: {{ include "hello-world.fullname" . }}
labels:
{{- include "hello-world.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "hello-world.selectorLabels" . | nindent 4 }}
这个类型应该是ClusterIP
修改为NodePort后重新升级后
[root@k8s-master01 helm]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-world NodePort 10.101.235.85 <none> 80:30412/TCP 27m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 20d
svc-1 ClusterIP 10.105.127.237 <none> 80/TCP 19d
svc-2 ClusterIP 10.104.19.243 <none> 80/TCP 19d
尽管如此,发现顶多是子pod所在节点ip去访问这个外部端口可以,但是通过clusterip是无法访问。
打脸。。仔细看看老师哪里也是从节点ip访问的。。
那么接下来这里也能访问通过了
Step8
重新修改deployment的镜像拉取为通过动态配置拉取
[root@k8s-master01 helm]# cat hello-world/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "hello-world.fullname" . }}
labels:
{{- include "hello-world.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "hello-world.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "hello-world.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "hello-world.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
修改的和老师的那个动态配置一样,然后发现hello-world项目根目录就自动有values.yaml,老师的字段和这里配置的基本吻合。
或者就是helm3就是一个规范直接把helm2的values配置yaml文件拿过来遵循了values2的一些原本的字段配置。
然后这里修改该values.yaml中镜像与tag与老师的一致
[root@k8s-master01 helm]# cat hello-world/values.yaml
# Default values for hello-world.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: wangyanglinux/myapp
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "v2"
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
podAnnotations: {}
podSecurityContext: {}
# fsGroup: 2000
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
service:
type: ClusterIP
port: 80
ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80
nodeSelector: {}
tolerations: []
affinity: {}
再次升级后就是wangyanglinux/myapp:v2的了
Step9
然后通过helm命令可以直接设置镜像版本
[root@k8s-master01 helm]# helm upgrade hello-world --set image.tag='v3' ./hello-world
Release "hello-world" has been upgraded. Happy Helming!
NAME: hello-world
LAST DEPLOYED: Tue Jan 17 15:20:00 2023
NAMESPACE: default
STATUS: deployed
REVISION: 5
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hello-world,app.kubernetes.io/instance=hello-world" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:80
这里要稍等片刻,才会生效成v3版本(可能是拉取(拉取应该是同步,不太可能),应该是部署过程需要点时间的,或者浏览器缓存。。)
这里是多刷新了几次后才生效的
Step10
关于原本的helm 项目的删除是helm delete
那么现在是uninstall,如
helm uninstall hello-world
为了更好地调整与其他软件包管理器的联系,将helm delete重命名为helm uninstall。
原本是删除后再次安装会因为release名称相同而无法安装(helm install --name release名称 release项目路径)
但这里实际上—name已经废弃
[root@k8s-master01 helm]# helm install --name hello-world ./hello-world
Error: unknown flag: --name
就直接第二个参数就是release名称,不分第二参数(选项)的参数(选项)名和参数(选项)值。。
但helm3即便是同名,也是可以安装的
[root@k8s-master01 helm]# helm install hello-world ./hello-world
NAME: hello-world
LAST DEPLOYED: Tue Jan 17 15:33:01 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hello-world,app.kubernetes.io/instance=hello-world" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:80
然后helm list的—deleted选项是废弃了
[root@k8s-master01 helm]# helm list --deleted
Error: unknown flag: --deleted
Step11
从上面最后一次安装hello-world项目后看到修订号为1
按老师原来的逻辑是回滚以使得之前删除的helm项目回归回来。
那么现在
[root@k8s-master01 helm]# helm rollback hello-world 1
Rollback was a success! Happy Helming!
虽然没有报错,但是我觉得应该是什么都没有发生。
必定这个1应该是最初修订号吧。
但修订号还是会按老师原来的逻辑一样会增加
[root@k8s-master01 helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
hello-world default 2 2023-01-17 15:37:09.608630758 +0800 CST deployed hello-world-0.1.0 1.16.0
那么按原来的逻辑从已删除的helm项目回滚出来还可以继续访问。这里本来就没有做什么,自然也是可以访问的。毕竟找不到删除之前的版本号了。。
但是helm3卸载其项目时候提供--keep-history选项以实现helm2中delete删除项目保留历史的作用,则再次安装同名release时则是安装不通过的
[root@k8s-master01 helm]# helm uninstall hello-world --keep-history
release "hello-world" uninstalled
[root@k8s-master01 helm]# helm install hello-world ./hello-world
Error: cannot re-use a name that is still in use
然后使用--all实现了helm2的—deleted选项于helm list的功能
[root@k8s-master01 helm]# helm list --all
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
hello-world default 2 2023-01-17 15:37:09.608630758 +0800 CST uninstalled hello-world-0.1.0 1.16.0
那么再次回滚到刚才保留历史的卸载的版本之前
[root@k8s-master01 helm]# helm rollback hello-world 1
Rollback was a success! Happy Helming!
那么按原来的逻辑从已删除的helm项目回滚出来还可以继续访问。只是默认向外暴漏的随机端口发生了变化。(好像每次安装/卸载后都会发生变化)
关于“回滚到比6之前的版本?”的疑问,其实当时老师的命令是helm list –deleted那么自然是查看包含已删除的,那么未删除的版本就是比该版本号更低咯。
关于强制删除,则取而代之的是helm uninstall不使用--keep-history选项即可
[root@k8s-master01 helm]# helm uninstall hello-world
release "hello-world" uninstalled
[root@k8s-master01 helm]# helm list --all
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
Step12
尝试运行的选项仍旧保留,只是要结合helm3的install命令调整下,并且结果有所不同,其它作用一样,也是仅尝试安装,不会产生实际的helm项目。
[root@k8s-master01 helm]# helm install --dry-run hello-world ./hello-world/
NAME: hello-world
LAST DEPLOYED: Tue Jan 17 15:59:06 2023
NAMESPACE: default
STATUS: pending-install
REVISION: 1
HOOKS:
---
# Source: hello-world/templates/tests/test-connection.yaml
apiVersion: v1
kind: Pod
metadata:
name: "hello-world-test-connection"
labels:
helm.sh/chart: hello-world-0.1.0
app.kubernetes.io/name: hello-world
app.kubernetes.io/instance: hello-world
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['hello-world:80']
restartPolicy: Never
MANIFEST:
---
# Source: hello-world/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: hello-world
labels:
helm.sh/chart: hello-world-0.1.0
app.kubernetes.io/name: hello-world
app.kubernetes.io/instance: hello-world
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
---
# Source: hello-world/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: hello-world
labels:
helm.sh/chart: hello-world-0.1.0
app.kubernetes.io/name: hello-world
app.kubernetes.io/instance: hello-world
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
spec:
type: NodePort
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: hello-world
app.kubernetes.io/instance: hello-world
---
# Source: hello-world/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
labels:
helm.sh/chart: hello-world-0.1.0
app.kubernetes.io/name: hello-world
app.kubernetes.io/instance: hello-world
app.kubernetes.io/version: "1.16.0"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: hello-world
app.kubernetes.io/instance: hello-world
template:
metadata:
labels:
app.kubernetes.io/name: hello-world
app.kubernetes.io/instance: hello-world
spec:
serviceAccountName: hello-world
securityContext:
{}
containers:
- name: hello-world
securityContext:
{}
image: "wangyanglinux/myapp:v2"
imagePullPolicy: IfNotPresent
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{}
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hello-world,app.kubernetes.io/instance=hello-world" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:80
运行结果比原来多了不知道多少呢。。。
作用一样,不会产生实际的helm项目
[root@k8s-master01 helm]# helm list
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
[root@k8s-master01 helm]# helm list --all
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
关键字词:helm,helm2,helm3,chart,k8s,kubernetes,install,no available release name found