我已经docker化了一个简单的 Spring Boot Rest api 应用程序,其中列出了 /employee 端点的员工。
我创建了一个舵图并使用图像更新了values.yml 名称,服务类型为 NodePort,服务端口为 31234。
应用程序配置为在端口 8085 上运行
在 localhost 5001 创建本地 docker 注册表并推送 图像到此注册表。所以values.yml下的镜像名称是localhost:5001/emp,tag是latest。
kubectl 获取节点 -o Wide 给出:
test-dev-control-plane 就绪控制平面 2d23h v1.27.3 172.18.0.3 Debian GNU/Linux 11 (bullseye) 5.15.133.1-microsoft-standard-WSL2 containerd://1.7.1
test-dev-worker Ready 2d23h v1.27.3 172.18.0.5 Debian GNU/Linux 11(牛眼)5.15.133.1-microsoft-standard-WSL2 containerd://1.7.1
test-dev-worker2 Ready 2d23h v1.27.3 172.18.0.2 Debian GNU/Linux 11(牛眼)5.15.133.1-microsoft-standard-WSL2 containerd://1.7.1
名称类型集群-IP 外部-IP 端口年龄
emp1-chart NodePort 10.96.181.143 31234:30296/TCP 2d19h kubernetes ClusterIP 10.96.0.1 443/TCP 2d23h
名称就绪状态重新开始
emp1-chart-7c48d49bd4-rd64w 1/1 运行 1(6 分 20 秒前)2d19h
http://172.18.0.2:31234/employee
http://172.18.0.3:31234/employee
http://172.18.0.5:31234/employee
我可以使用以下命令查看节点中的图像:
它列出了图像:
localhost:5001/employee1 最新 f784fbf148a06 532MB
helm 图表 value.yml:
replicaCount: 1
image:
repository: localhost:5001/employee1
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
# Specifies whether a service account should be created
create: true
# Automatically mount a ServiceAccount's API credentials?
automount: 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: {}
podLabels: {}
podSecurityContext: {}
# fsGroup: 2000
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
service:
type: NodePort
port: 31234
ingress:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
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
# Additional volumes on the output Deployment definition.
volumes: []
# - name: foo
# secret:
# secretName: mysecret
# optional: false
# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true
nodeSelector: {}
tolerations: []
affinity: {}
这对我有用:)
kubectl port-forward <pod-name> <local-port>:<remote-port>
kubectl port-forward pods/abc 31234:8085
其中 abc 是我的 Pod 名称,31234 是 Helm Chart Values.yml 中定义的 NodePort,它映射到我的Deployment.yml 中的容器端口,8085 是我的 Spring Boot Rest api 应用程序中定义为服务器端口的端口。
一旦我这样做了,我就可以将其视为输出:
Forwarding from 127.0.0.1:31234 -> 8085
Forwarding from [::1]:31234 -> 8085
Handling connection for 31234
Handling connection for 31234
然后我使用运行我的应用程序 http://localhost:31234/employee 这给了我想要的结果:)