openseach helm部署

opensearch部署安装

前置条件

需要有opensearchproject/opensearch和busy镜像,环境中已经安装k8s和helm;文章主要内容涉及opensearch的helm部署和证书配置验证

1、opensearch证书配置

opensearch配置证书,由于jaeger中读取证书的时候默认采取更加安全的方式,默认不会读取domainName参数作为域名,因此需要将证书域名配置在SubjectAltName(对应下面命令中出现的csr.conf中的内容)中生成命令如下

  • 首先生成root-ca.pem根证书和key
openssl genrsa -out root-key.pem  4096

openssl req -x509 -new -nodes -key root-key.pem -sha256 -days 3650 -out root-ca.pem -config csr.conf

csr.conf 内容

[req]
default_bits = 2048
prompt = no
default_md = sha256
distinguished_name = dn
req_extensions = req_ext

[dn]
C = CN
ST = tianjin
L = ceshi
O = ceshi
OU = ceshi
CN = opensearch-cluster-master

[req_ext]
subjectAltName = @alt_names

[alt_names]
DNS.1 = opensearch-cluster-master
DNS.2 = opensearch-cluster-master-0
DNS.3 = opensearch-cluster-master-1
DNS.4 = opensearch-cluster-master-2
  • 生成客户端证书
# 生成客户端证书key
openssl genrsa -out node-key.pem 4096

# 生成客户端证书签名请求
openssl req -new -key node-key.pem -out node.csr -config csr.conf

# 使用根证书签名生成客户端证书
openssl x509 -req -in  node.csr  -CA root-ca.pem  -CAkey root-key.pem  -CAcreateserial -out node-cert.pem -days 365 -extensions req_ext -extfile csr.conf

2、 将证书添加到secret中

kubectl -n xp2  create secret  generic  opensearch-secret  --from-file=node-cert.pem --from-file=node-key.pem --from-file=root-ca.pem

3、helm部署中values.yaml配置

需要修改的配置如下(下方配置均在values.yaml中):

  • config相关配置,修改其中opensearch.yml中对于tls的配置
config:
  opensearch.yml: |
    cluster.name: opensearch-cluster
    plugins:
      security:
        ssl:
          transport:
            enabled: true
            pemcert_filepath: /usr/share/opensearch/data/certs/node-cert.pem
            pemkey_filepath: /usr/share/opensearch/data/certs/node-key.pem
            pemtrustedcas_filepath: /usr/share/opensearch/data/certs/root-ca.pem
            enforce_hostname_verification: false
            resolve_hostname: false
          http:
            enabled: true
            pemcert_filepath: /usr/share/opensearch/data/certs/node-cert.pem
            pemkey_filepath: /usr/share/opensearch/data/certs/node-key.pem
            pemtrustedcas_filepath: /usr/share/opensearch/data/certs/root-ca.pem
        nodes_dn:
          - "CN=opensearch-cluster-master,OU=kylin,O=kylin,L=kylin,ST=tianjin,C=CN"
          - "CN=opensearch-cluster-master-0,OU=kylin,O=kylin,L=kylin,ST=tianjin,C=CN"
          - "CN=opensearch-cluster-master-1,OU=kylin,O=kylin,L=kylin,ST=tianjin,C=CN"
          - "CN=opensearch-cluster-master-2,OU=kylin,O=kylin,L=kylin,ST=tianjin,C=CN"
        allow_unsafe_democertificates: true

  • extraEnvs相关配置,配置opensearch服务访问密码
extraEnvs:
  - name: OPENSEARCH_INITIAL_ADMIN_PASSWORD
    value: Kylin@2025

  • secretMounts相关配置,映射证书到服务中
secretMounts:
  - name: certs-volume
    secretName: opensearch-secret
    path: /usr/share/opensearch/data/certs/
  • 镜像配置,修改成自己可以下载的或者可以访问到的相关对应镜像即可
image:
  repository: "opensearchproject/opensearch"
  # override image tag, which is .Chart.AppVersion by default
  tag: ""
  pullPolicy: "IfNotPresent"
  • persistence配置,配置opensearch存储,是否持久化(卸载服务数据不丢失)
persistence:
  enabled: true
  enableInitChown: false
  image: busybox
  imageTag: 1.37.0
  labels:
    enabled: false
    additionalLabels: {}
  storageClass: "nfs"
  accessModes:
    - ReadWriteOnce
  size: 8Gi
  annotations: {}

4、安装

  • opensearch安装,在opensearch目录下(values.yaml所在目录)
helm -n xp install opensearch .

5、验证

  • 验证opensearch服务
    下面的ip地址为ks8查询到的opensearch-cluster-master服务的ip地址命令如下
kubectl get svc -n xp2
curl https://10.77.3.213:9200 -u 'admin:ceshi@2025' --insecure

结果如下,服务正常

{
  "name" : "opensearch-cluster-master-2",
  "cluster_name" : "opensearch-cluster",
  "cluster_uuid" : "ndvHTbgmTlmmIhGbYJSHoQ",
  "version" : {
    "distribution" : "opensearch",
    "number" : "2.18.0",
    "build_type" : "tar",
    "build_hash" : "99a9a81da366173b0c2b963b26ea92e15ef34547",
    "build_date" : "2024-10-31T19:08:39.157471098Z",
    "build_snapshot" : false,
    "lucene_version" : "9.12.0",
    "minimum_wire_compatibility_version" : "7.10.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "The OpenSearch Project: https://opensearch.org/"
}

  • 验证证书
    在hosts中添加服务名和ip映射之后执行下面命令
curl --cacert ../certs2/node-cert.pem  https://opensearch-cluster-master:9200 -u 'admin:ceshi@2025'

结果如下,证书可用

{
  "name" : "opensearch-cluster-master-2",
  "cluster_name" : "opensearch-cluster",
  "cluster_uuid" : "ndvHTbgmTlmmIhGbYJSHoQ",
  "version" : {
    "distribution" : "opensearch",
    "number" : "2.18.0",
    "build_type" : "tar",
    "build_hash" : "99a9a81da366173b0c2b963b26ea92e15ef34547",
    "build_date" : "2024-10-31T19:08:39.157471098Z",
    "build_snapshot" : false,
    "lucene_version" : "9.12.0",
    "minimum_wire_compatibility_version" : "7.10.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "The OpenSearch Project: https://opensearch.org/"
}
### 使用 Helm 进行应用部署的教程及示例 #### Helm 的基本概念 Helm 是 Kubernetes 应用程序的包管理工具,它通过 Chart 来描述一组 Kubernetes 资源对象。Chart 可以看作是一个模板集合,用于简化复杂应用程序的部署过程[^3]。 #### 安装 Helm 在开始之前,需要先安装 Helm 工具本身。可以通过官方文档获取最新的安装指南。通常情况下,可以使用以下命令来完成安装: ```bash curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash ``` 确认安装成功后,运行 `helm version` 查看当前版本号[^2]。 #### 初始化本地环境 如果需要连接到远程 Chart 仓库,则需执行如下操作初始化 Helm 环境并添加默认仓库: ```bash helm repo add stable https://charts.helm.sh/stable helm repo update ``` 这一步会更新可用 Charts 列表,并允许后续从中拉取所需资源。 #### 创建第一个 Deployment (MySQL 示例) 作为入门练习之一,这里展示如何利用 Helm 部署 MySQL 数据库服务: 1. **搜索目标 chart** 执行下面这条指令找到合适的 mysql chart 版本信息。 ```bash helm search repo mysql ``` 2. **安装指定 chart** 下面的例子展示了怎样基于稳定版 charts 中的标准配置去启动一个新的实例。 ```bash helm install my-mysql stable/mysql --set mysqlRootPassword=yourpassword,mariadb.enabled=false ``` 此处设置了 root 密码以及禁用了 mariadb 组件选项。 3. **验证 Pod 是否正常工作** 检查新创建出来的 pod 当前状态是否处于 Running 或 Ready 状态下。 ```bash kubectl get pods ``` 4. **访问已部署的服务端口映射情况** 如果想测试外部能否连入该数据库服务器的话,可通过 port-forwarding 技术实现临时暴露功能。 ```bash kubectl port-forward svc/my-mysql 3306:3306 & ``` #### 更改现有 Chart 设置(Jenkins 实例调整时区为例) 有时原生提供的 templates 并不完全满足业务需求场景下的定制化参数设定要求。比如 Jenkins 默认设置的时间戳格式不符合中国地区习惯等问题就需要额外处理解决办法: 1. 编辑对应 StatefulSet YAML 文件路径位置; 2. 添加 env 参数字段声明新的 TZ 值等于 Asia/Shanghai 字符串表示形式; ```yaml spec: template: spec: containers: - name: jenkins image: "jenkins/jenkins:lts" ... env: - name: TZ value: "Asia/Shanghai" ``` 3. 更新改动后的 manifest 再次 apply 提交至集群生效即可[^4]。 --- ### 总结 上述内容涵盖了从基础理论认识到实际动手演练整个流程环节的知识要点介绍。希望可以帮助读者更好地理解掌握关于 Helm 的核心技能知识点[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值