国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Devops系列二(使用helm chart,將java應用發(fā)布部署至k8s的示例)

這篇具有很好參考價值的文章主要介紹了Devops系列二(使用helm chart,將java應用發(fā)布部署至k8s的示例)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、接著上一篇的話

docker鏡像已經(jīng)有了,本文我們將接著演示如何使用helm部署應用到k8s。
分為兩大部分:

  • 制作helm chart,推送到私有倉庫nexus
  • helm拉取chart,部署到k8s

二、制作helm chart

要求你先安裝helm,隨便一臺linux機器即可,不要求你要有k8s或者docker環(huán)境。

xxx@local:~/Downloads$ wget https://get.helm.sh/helm-v3.12.1-linux-amd64.tar.gz
--2023-06-30 10:49:03--  https://get.helm.sh/helm-v3.12.1-linux-amd64.tar.gz
正在解析主機 get.helm.sh (get.helm.sh)... 152.199.39.108, 2606:2800:247:1cb7:261b:1f9c:2074:3c
正在連接 get.helm.sh (get.helm.sh)|152.199.39.108|:443... 已連接。
已發(fā)出 HTTP 請求,正在等待回應... 200 OK
長度: 16036346 (15M) [application/x-tar]
正在保存至: “helm-v3.12.1-linux-amd64.tar.gz”

helm-v3.12.1-linux- 100%[===================>]  15.29M  1.19MB/s    用時 13s   

2023-06-30 10:49:18 (1.14 MB/s) - 已保存 “helm-v3.12.1-linux-amd64.tar.gz” [16036346/16036346])

xxx@local:~/Downloads$ tar -xf helm-v3.12.1-linux-amd64.tar.gz 

xxx@local:~/Downloads$ sudo mv linux-amd64/helm /usr/local/bin/helm
[sudo] xxx 的密碼: 

xxx@local:~/Downloads$ helm version
version.BuildInfo{Version:"v3.12.1", GitCommit:"f32a527a060157990e2aa86bf45010dfb3cc8b8d", GitTreeState:"clean", GoVersion:"go1.20.4"}

xxx@local:~/Downloads$ helm repo list
NAME       URL                               
bitnami    https://charts.bitnami.com/bitnami

1、創(chuàng)建helm模板

helm creta java

Devops系列二(使用helm chart,將java應用發(fā)布部署至k8s的示例),java,kubernetes這里,我刪除了沒用到的一些文件,最后保留的見下:
Devops系列二(使用helm chart,將java應用發(fā)布部署至k8s的示例),java,kubernetes
templates下的三個文件就是對應K8S容器的三個yaml,沒有什么好說的,helm這里額外增加了一個values.yaml文件,它是用來替換templates下的yaml文件里的變量。

那有人要問了,values.yaml文件里的變量可以替換嗎?

在helm install的時候,你仍然可以替換values.yaml中的變量。所以我這設計的所有java應用,不同的環(huán)境,都使用同一個helm chart。

不同應用存在環(huán)境的差異,這個問題也就因此解決了。

2. deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.appName }}
  namespace: {{ .Values.namespace }}
  labels:
    app: {{ .Values.appName }}
spec:
  progressDeadlineSeconds: 600
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: {{ .Values.appName }}
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        app: {{ .Values.appName }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets: 
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
        - name: {{ .Values.appName }}
          env:
            - name: TZ
              value: Asia/Shanghai
            - name: APPNAME
              value: {{ .Values.appName }}
            - name: CONFIG_SERVICE_ADDR
              value: {{ .Values.env.configServiceAddr }}
            - name: CONFIG_SERVICE_NAMESPACE
              value: {{ .Values.env.configServiceNameSpace }}
            - name: CONFIG_SERVICE_GROUP
              value: {{ .Values.env.configServiceGroup }}
            - name: CONFIG_EPHEMERAL
              value: 'false'
            - name: CONFIG_SERVICE_ENABLED
              value: '{{ .Values.env.configServiceEnabled }}'
            - name: spring.cloud.nacos.config.accessKey
              value: {{ .Values.env.configAccessKey }}
            - name: spring.cloud.nacos.config.secretKey
              value: {{ .Values.env.configSecretKey }}
            - name: spring.cloud.nacos.discovery.accessKey
              value: {{ .Values.env.configAccessKey }}
            - name: spring.cloud.nacos.discovery.secretKey
              value: {{ .Values.env.configSecretKey }}
            - name: JAVA_OPTS
              value: {{ .Values.env.javaOpts }}

          image: "{{ .Values.image.repository }}{{ .Values.appName }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /mgm/health
              port: {{ .Values.service.port }}
              scheme: HTTP
            initialDelaySeconds: 1
            periodSeconds: 5
            successThreshold: 1
            timeoutSeconds: 3
          startupProbe:
            failureThreshold: 22
            httpGet:
              path: /mgm/health
              port: {{ .Values.service.port }}
              scheme: HTTP
            initialDelaySeconds: 25
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          resources:
            limits:
              cpu: {{ .Values.resource.limitCpu }}
              memory: {{ .Values.resource.limitMemory }}
            requests:
              cpu: {{ .Values.resource.requestCpu }}
              memory: {{ .Values.resource.requestMemory }}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

3、values.yaml

# Default values for java.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

namespace: java-service

appName: devops-service

replicaCount: 1

env:
  javaOpts: 
  # consul
  configServiceEnabled: true
  configServiceHost: 192.168.10.19
  configServicePort: 8500
  # nacos
  configServiceAddr: 192.168.5.28:8848
  configServiceNameSpace: a5fdc665-4267-462e-9b03-d363984d9963
  configServiceGroup: DEFAULT_GROUP
  configAccessKey:
  configSecretKey:

image:
  repository: 192.168.5.6:8086/xxx/
  pullPolicy: IfNotPresent
  # Overrides the image tag whose default is the chart appVersion.
  tag: 1.0.7

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""


podAnnotations: {}

podSecurityContext: {}
  # fsGroup: 2000

securityContext: {}
  # capabilities:
  #   drop:
  #   - ALL
  # readOnlyRootFilesystem: true
  # runAsNonRoot: true
  # runAsUser: 1000

service:
  type: NodePort
  port: 8085

ingress:
  enabled: false
  className: "nginx"
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  hosts:
    - host: devops-service.ztyedu.net
      paths:
        - path: /
          pathType: ImplementationSpecific
  tls: []
  #  - secretName: chart-example-tls
  #    hosts:
  #      - chart-example.local

resource:
  limitCpu: '2'
  limitMemory: 2Gi
  requestCpu: 250m
  requestMemory: 2Gi

autoscaling:
  enabled: false
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}

4. service.yaml

apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.appName }}
  namespace: {{ .Values.namespace }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: {{ .Values.service.port }}
      protocol: TCP
      name: {{ .Values.appName }}
  selector:
    app: {{ .Values.appName }}
  sessionAffinity: None

5、 ingress.yaml

{{- if .Values.ingress.enabled -}}
{{- $fullName := .Values.appName -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
  {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
  {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
  {{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
  name: {{ $fullName }}
  namespace: {{ .Values.namespace }}
spec:
  {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
  ingressClassName: {{ .Values.ingress.className }}
  {{- end }}
  {{- if .Values.ingress.tls }}
  tls:
    {{- range .Values.ingress.tls }}
    - hosts:
        {{- range .hosts }}
        - {{ . | quote }}
        {{- end }}
      secretName: {{ .secretName }}
    {{- end }}
  {{- end }}
  rules:
    {{- range .Values.ingress.hosts }}
    - host: {{ .host | quote }}
      http:
        paths:
          {{- range .paths }}
          - path: {{ .path }}
            {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
            pathType: {{ .pathType }}
            {{- end }}
            backend:
              {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
              service:
                name: {{ $fullName }}
                port:
                  number: {{ $svcPort }}
              {{- else }}
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
              {{- end }}
          {{- end }}
    {{- end }}
{{- end }}

6、Chart.yaml

version是helm chart的版本號,應用的版本號見values.yaml文件中的image.tag(每次構(gòu)建版本號都會追加1)

apiVersion: v2
name: java
description: java demo

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.8

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

三、推送chart至helm私庫

1、添加 helm repo

xxx@local:~$ helm repo list
NAME    URL                               
bitnami https://charts.bitnami.com/bitnami

# 新增helm倉庫
xxx@local:~$ helm repo add nexus http://150xxxx9916:123456@192.168.5.6:8081/repository/xh-helm/
"nexus" has been added to your repositories

xxx@local:~$ helm repo list
NAME    URL                                                           
bitnami https://charts.bitnami.com/bitnami                            
nexus   http://150xxxx9916:123456@192.168.5.6:8081/repository/xh-helm/

2、安裝helm推送插件

xxx@local:~$ helm plugin install --version master https://gitee.com/mirrors_sonatype-nexus-community/helm-nexus-push.git
Installed plugin: nexus-push

3、構(gòu)建并推送

# 構(gòu)建chart
xxx@local:~/Downloads$  helm package java
Successfully packaged chart and saved it to: /home/xxx/Downloads/java-0.1.8.tgz

# 推送chart到私有倉庫
xxx@local:~/Downloads$ helm nexus-push nexus java-0.1.8.tgz -u 150xxxx9916 -p 123456
Pushing java-0.1.8.tgz to repo http://150xxxx9916:123456@192.168.5.6:8081/repository/xh-helm//...
  HTTP/1.1 100 Continue
  
  HTTP/1.1 200 OK
  Date: Fri, 30 Jun 2023 10:16:44 GMT
  Server: Nexus/3.37.3-02 (OSS)
  X-Content-Type-Options: nosniff
  Content-Security-Policy: sandbox allow-forms allow-modals allow-popups allow-presentation allow-scripts allow-top-navigation
  X-XSS-Protection: 1; mode=block
  Content-Length: 0
  
Done

四、總結(jié)

登錄nexus,查看上傳的chart。

Devops系列二(使用helm chart,將java應用發(fā)布部署至k8s的示例),java,kubernetes
Devops系列二(使用helm chart,將java應用發(fā)布部署至k8s的示例),java,kubernetes
可以看到,chart上傳成功。
接下里,就是我們在k8s的控制臺,將在下一篇文章進行描述。文章來源地址http://www.zghlxwxcb.cn/news/detail-524482.html

到了這里,關于Devops系列二(使用helm chart,將java應用發(fā)布部署至k8s的示例)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • k8s實戰(zhàn)3-使用Helm在AKS上發(fā)布應用

    k8s實戰(zhàn)3-使用Helm在AKS上發(fā)布應用

    AKS(Azure Kubenetes Service)是微軟云azure上的K8s服務。 主要分為三步 1 連接到AKS 2 用kubectl發(fā)布應用 3 用Helm發(fā)布應用 1 登錄 az login 2 連接 dp-npr-dsm-aks(Dsm項目的AKS) az account set --subscription {{subID}} az aks get-credentials --resource-group {{resource-group-name}}?--name {{aks-name}} --admin 3 測試是否連接成

    2024年02月13日
    瀏覽(24)
  • Helm Chart三分鐘輕松掌握

    ? 我們的日常工作中需創(chuàng)建、修改和部署Helm Chart,以管理應用程序的部署。Helm是Kubernetes的應用程序包管理器,它負責協(xié)調(diào)應用程序的下載、安裝和部署。 chart就是一個描述Kubernetes相關資源的文件集合。 ? 那么為什么會有人使用 Helm 呢? Helm 通過模板化方法在 Kubernetes 中更

    2023年04月09日
    瀏覽(25)
  • Helm-從0手動創(chuàng)建charts

    創(chuàng)建 chart 目錄結(jié)構(gòu): 創(chuàng)建 Chart.yaml : 創(chuàng)建 templates 目錄: 創(chuàng)建 deployment.yaml: 以上完成后就可以使用 helm 部署,部署名為 my-nginx 的應用: 查看創(chuàng)建的應用: 查看創(chuàng)建的實際資源: 繼續(xù)創(chuàng)建 service.yaml: 創(chuàng)建 values.yaml: 修改 deployment.yaml,注入變量,改為模板形式: 修改

    2024年02月16日
    瀏覽(14)
  • Helm Chart安裝EFK并驗證功能

    Helm Chart安裝EFK并驗證功能

    本文介紹如何通過Helm Chart方式快速在Kubernetes環(huán)境中搭建EFK(Elasticsearch,F(xiàn)ilebeat,Kibana)V8.5.1 日志收集系統(tǒng)并驗證其功能。如果僅對安裝有興趣請直接食用“EFK(Elasticsearch,F(xiàn)ilebeat,Kibana)V8.5.1 安裝”章節(jié)。 日志收集系統(tǒng)背景需求 隨著現(xiàn)在各種軟件系統(tǒng)的復雜度越來越高,

    2024年02月09日
    瀏覽(12)
  • 【筆記】Helm-3 主題-6 Chart倉庫指南

    【筆記】Helm-3 主題-6 Chart倉庫指南

    Chart倉庫指南 本節(jié)介紹如何創(chuàng)建和使用chart倉庫。在高層級中,chart倉庫是打包的chart存儲和分享的位置。 社區(qū)的Helm chart倉位于 Artifact Hub ,歡迎加入。不過Helm也可以創(chuàng)建并運行您自己的chart倉庫。該指南將介紹如何操作。 Artifact Hub 先決條件 先閱讀 快速開始 閱讀 Charts 文檔

    2024年01月18日
    瀏覽(48)
  • DevOps系列文章 之 Java使用jgit管理git倉庫

    DevOps系列文章 之 Java使用jgit管理git倉庫

    最近設計基于gitops新的CICD方案,需要通過java讀寫git倉庫,這里簡單記錄下。 在jgit中,存在最核心的三個組件:Git類,Repository類。Git類中包含了push commit之類的常見git操作,而Repository則實現(xiàn)了倉庫的初始化和基本的管理功能。 Git類的實例都會持有一個Repository實例。 Repositor

    2024年02月12日
    瀏覽(25)
  • 云原生Kubernetes:簡化K8S應用部署工具Helm

    云原生Kubernetes:簡化K8S應用部署工具Helm

    目錄 一、理論 1.HELM ?編輯 2.部署HELM2 3.部署HELM3(2to3方式) 4.部署HELM3(單獨安裝) 二、實驗 1.部署 HELM2 2.部署HELM3(2to3方式) 3.部署HELM3(單獨安裝) 三、問題 1.api版本過期 2.helm初始化報錯 3.pod狀態(tài)為ImagePullBackOff 4.helm?命令顯示?no repositories to show?的錯誤 5.Helm安裝報錯

    2024年02月07日
    瀏覽(103)
  • 什么是Helm?它是如何提升云原生應用私有化部署效率的

    轉(zhuǎn)載至我的博客 ,公眾號:架構(gòu)成長指南 試想一下,如果有一個項目有50 個微服務,每個微服務都有service、deployment、ingress、pvc等 yaml 文件,算下來大概有 200 個文件,然后這個項目需要基于k8s進行私有化交付,如果是你會怎么快速部署應用? 首先讓我們先思考一下 200 個文

    2024年02月03日
    瀏覽(26)
  • DevOps系列文章 之 Gitlab+Docker自動部署SpringBoot

    DevOps系列文章 之 Gitlab+Docker自動部署SpringBoot

    以下服務器的操作系統(tǒng)均為Centos7 服務器A:Gitlab 服務器B:GitlabRunner、Docker、docker-compose、Java1.8、maven3.6.3、git ps:這里可以把服務器B的GitlabRunner、Java1.8、maven3.6.3、git單獨提出來,獨立部署,需要java的原因是maven,maven用于打包。 應用服務器B就只需要docker和docker-compose就可以

    2024年02月13日
    瀏覽(24)
  • DevOps系列文章之 GitlabCICD自動化部署SpringBoot項目

    DevOps系列文章之 GitlabCICD自動化部署SpringBoot項目

    本文主要記錄如何通過Gitlab CI/CD自動部署SpringBoot項目jar包。 準備三臺 CentOS7服務器,分別部署以下服務: 序號 系統(tǒng) IP 服務 1 CentOS7 192.168.56.10 Gitlab 2 CentOS7 192.168.56.11 Runner (安裝Docker) 3 CentOS7 192.168.56.12 SpringBoot 項目 jar 包(安裝jdk、maven等) 上述服務也可以只用一臺CentOS

    2024年02月13日
    瀏覽(12)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包