helm部署易用ubuntu

Ethereal Lv4

1. 前置条件

1.1 配置本地存储

1
2
3
4
5
6
# local path-provisioner # https://github.com/rancher/local-path-provisioner
wget https://raw.githubusercontent.com/rancher/local-path-provisioner/v0.0.29/deploy/local-path-storage.yaml
sed -i 's#/opt/local-path-provisioner#/opt/k8s-local-path-storage#g'
crictl pull dhub.kubesre.xyz/rancher/local-path-provisioner:v0.0.29
ctr -n k8s.io i tag dhub.kubesre.xyz/rancher/local-path-provisioner:v0.0.29 docker.io/rancher/local-path-provisioner:v0.0.29
k apply -f local-path-storage.yaml

1.2 开启特性门控

1
2
3
4
5
6
# 开启StatefulSetAutoDeletePVC特性门控
# 此门控在1.27已经默认启用
sudo vim /etc/kubernetes/manifests/kube-controller-manager.yaml
# 添加参数
- --feature-gates=StatefulSetAutoDeletePVC=true
# 关闭保存后kube-controller-manager会自动重新加载

2. 配置文件

2.1 结构

1
2
3
4
5
6
7
8
9
10
11
12
tree .
.
├── charts
├── Chart.yaml
├── templates
│   ├── _helpers.tpl
│   ├── NOTES.txt
│   ├── service.yaml
│   ├── statefulset.yaml
│   └── tests
│   └── test-connection.yaml
└── values.yaml

2.2 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# templates/NOTES.txt
1. Get the application URL by running these commands:
{{- if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "ubuntu.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "ubuntu.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}


# templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: {{ include "ubuntu.fullname" . }}-ssh
labels:
{{- include "ubuntu.labels" . | nindent 4 }}
spec:
type: NodePort
ports:
- port: 22
targetPort: 22
protocol: TCP
name: ssh
selector:
{{- include "ubuntu.selectorLabels" . | nindent 4 }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "ubuntu.fullname" . }}
labels:
{{- include "ubuntu.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "ubuntu.selectorLabels" . | nindent 4 }}


# templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "ubuntu.fullname" . }}
labels:
{{- include "ubuntu.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "ubuntu.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "ubuntu.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.customCommand }}
command:
{{- range .command }}
- {{ . | quote }}
{{- end }}
args:
{{- range .args }}
- {{ . | quote }}
{{- end }}
{{- end }}
ports:
- name: ssh
containerPort: 22
protocol: TCP
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
{{- with .Values.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 12 }}
{{- end }}
securityContext:
privileged: {{ .Values.privileged }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- name: default-volume
mountPath: {{ .Values.defaultMountPath }}
{{- if .Values.sshConfig.enabled }}
- name: ssh-private-config
mountPath: {{ .Values.sshConfig.mountPath }}{{ .Values.sshConfig.idFile }}
- name: ssh-public-config
mountPath: {{ .Values.sshConfig.mountPath }}{{ .Values.sshConfig.idFile }}.pub
{{- end }}
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if or (ne (len .Values.volumes) 0) (.Values.sshConfig.enabled) }}
volumes:
{{- end }}
{{- if .Values.sshConfig.enabled }}
- name: ssh-private-config
hostPath:
path: {{ .Values.sshConfig.hostPath }}{{ .Values.sshConfig.idFile }}
- name: ssh-public-config
hostPath:
path: {{ .Values.sshConfig.hostPath }}{{ .Values.sshConfig.idFile }}.pub
{{- end }}
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
persistentVolumeClaimRetentionPolicy:
whenDeleted: Delete
whenScaled: Delete
volumeClaimTemplates:
- metadata:
name: default-volume
spec:
accessModes:
- ReadWriteOnce
storageClassName: # Default values for ubuntu.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/
replicaCount: 1

# This is local storage request
storage: 1Gi

# This is default mount path for main storage
defaultMountPath: "/home/ubuntu"

# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/
image:
repository: ubuntu
# This sets the pull policy for images.
pullPolicy: IfNotPresent

# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/
service:
# This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types
type: ClusterIP
# This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports
port: 80

# This is sshConfig mapping from host machine
sshConfig:
enabled: false
idFile: id_ed25519
hostPath: /home/ethereal/.ssh/
mountPath: /root/.ssh/

# This custom command for some images
customCommand:
command: [ "/bin/bash", "-c", "--" ]
args: [ "sed -i s@/archive.ubuntu.com/@/mirrors.tuna.tsinghua.edu.cn/@g /etc/apt/sources.list && apt-get update && apt-get install -y openssh-server && echo -e \"PermitRootLogin yes\n$(yes '020402' | passwd root)\" | tee -a /etc/ssh/sshd_config && service ssh restart || exit 1; while true; do sleep 3600; done;" ]

# This is to use privileged container
privileged: false

# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
readinessProbe:
exec:
command:
- /bin/sh
- -c
- service ssh status | grep 'running' # check SSH service

livenessProbe: []

# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
imagePullSecrets: []

# This is for setting Kubernetes Annotations to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
podAnnotations: {}
# This is for setting Kubernetes Labels to a Pod.
# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
podLabels: {}

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

# Additional volumes on the output Deployment definition.
volumes: []

# Additional volumeMounts on the output Deployment definition.
volumeMounts: []

tolerations: []

affinity: {}ditional volumeMounts on the output Deployment definition.
volumeMounts: []

tolerations: []

affinity: {}

3. 参考

特性门控 | Kubernetes

StatefulsetAutoDeletePVC default value is true in 1.27 · Issue #43976 · kubernetes/website (github.com)

kube-controller-manager panic happend when add StatefulSetAutoDeletePVC feature gate and create statefuleset with volumeClaimTemplates · Issue #113319 · kubernetes/kubernetes (github.com)

kubernetes persistentVolumeClaim保留机制 - 若-飞 - 博客园 (cnblogs.com)

Kubernetes 1.27: StatefulSet PVC 自动删除(beta) | Kubernetes

如何通过Helm模板传递数组?-腾讯云开发者社区-腾讯云 (tencent.com)

用Dockerfile创建一个具有ssh服务的基础Ubuntu镜像_带有sshd的乌班图镜像-CSDN博客

  • Title: helm部署易用ubuntu
  • Author: Ethereal
  • Created at: 2024-09-28 16:47:03
  • Updated at: 2024-11-05 20:39:36
  • Link: https://ethereal-o.github.io/2024/09/28/helm部署易用ubuntu/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments