Kubernetes 基础环境搭建

举报
tea_year 发表于 2024/11/21 14:24:08 2024/11/21
【摘要】 Kubernetes 安装使用 KubeKey 安装下载KK# 下载 kubekeyexport KKZONE=cncurl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -# 生成配置文件 kk create config --with-kubernetes v1.25.3kk create config --with-ku...

Kubernetes 安装

使用 KubeKey 安装

下载KK

# 下载 kubekey
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.7 sh -
# 生成配置文件 
kk create config  --with-kubernetes v1.25.3
kk create config  --with-kubernetes v1.23.15

编辑配置文件

apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: node1, address: 172.17.0.114, user: root, password: "sR00tgemUKB"}
  - {name: node2, address: 172.17.0.115, user: root, password: "sRgemUKB"}
  roleGroups:
    etcd:
    - node1
    control-plane: 
    - node1
    worker:
    - node1
    - node2
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers 
    # internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.25.3
    clusterName: cluster.local
    autoRenewCerts: true
    containerManager: containerd

安装

./kk create cluster -f config-sample.yaml

验证

 

Jenkins 安装

下载安装包

# https://pkg.jenkins.io/redhat-stable/
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
  

安装

  yum install fontconfig java-11-openjdk
  yum install jenkins-2.401.3-1.1.noarch

配置

# 修改 jenkins 启动用户为root
User=root
Group=root

MySQL 安装

 添加仓库

# 添加仓库
helm repo add bitnami https://charts.bitnami.com/bitnami

修改 Value

cp values.yaml values-ruoyi.yaml

global:
  imageRegistry: ""
  ## E.g.
  ## imagePullSecrets:
  ##   - myRegistryKeySecretName
  ##
  imagePullSecrets: []
  storageClass: "openebs-data"   # 修改为自己环境里的storageClass

auth:
  rootPassword: "yperygM3zqyRhozaR9ypJujEG0M"   #修改 root 密码
  createDatabase: false                         # 可以同时建库
  ## @param auth.database Name for a custom database to create
  ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-on-first-run
  ##
  database: "my_database"
  ## @param auth.username Name for a custom user to create
  ## ref: https://github.com/bitnami/containers/tree/main/bitnami/mysql#creating-a-database-user-on-first-run
  ##
  username: ""
  ## @param auth.password Password for the new user. Ignored if existing secret is provided
  ##
  password: ""

安装


helm -n middleware install mysql-ruoyi mysql -f mysql/values-ruoyi.yaml

Bash
[root@iZ8vbevtkgho7jiirl3snwZ helm]# helm -n middleware install mysql-ruoyi mysql -f mysql/values-ruoyi.yaml
NAME: mysql-ruoyi
LAST DEPLOYED: Thu Aug 10 18:19:58 2023
NAMESPACE: middleware
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: mysql
CHART VERSION: 9.10.10
APP VERSION: 8.0.34

** Please be patient while the chart is being deployed **

Tip:

  Watch the deployment status using the command: kubectl get pods -w --namespace middleware

Services:

  echo Primary: mysql-ruoyi.middleware.svc.cluster.local:3306

Execute the following to get the administrator credentials:

  echo Username: root
  MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace middleware mysql-ruoyi -o jsonpath="{.data.mysql-root-password}" | base64 -d)

To connect to your database:

  1. Run a pod that you can use as a client:

      kubectl run mysql-ruoyi-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.0.34-debian-11-r8 --namespace middleware --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash

  2. To connect to primary service (read/write):

      mysql -h mysql-ruoyi.middleware.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"

验证

MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace middleware mysql-ruoyi -o jsonpath="{.data.mysql-root-password}" | base64 -d)

[root@node1 ~]# kubectl run mysql-ruoyi-client --rm --tty -i --restart='Never' --image  docker.io/bitnami/mysql:8.0.34-debian-11-r8 --namespace middleware --env MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD --command -- bash

I have no name!@mysql-ruoyi-client:/$ mysql -h mysql-ruoyi.middleware.svc.cluster.local -uroot -p"$MYSQL_ROOT_PASSWORD"

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| nacos_ruoyi        |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.01 sec)

Redis 安装

添加仓库

# 添加仓库
helm repo add bitnami https://charts.bitnami.com/bitnami

修改 Value

global:
  imageRegistry: ""
  ## E.g.
  ## imagePullSecrets:
  ##   - myRegistryKeySecretName
  ##
  imagePullSecrets: []
  storageClass: "openebs-data"
  redis:
    password: "ruoyi"

## @param architecture Redis® architecture. Allowed values: `standalone` or `replication`
##
architecture: standalone    #测试环境只启单实例

安装

helm -n middleware install redis-ruoyi redis -f redis/values-ruoyi.yaml

Bash
[root@node1 helm]# helm -n middleware install redis-ruoyi redis -f redis/values-ruoyi.yaml

NAME: redis-ruoyi
LAST DEPLOYED: Thu Aug 10 22:45:58 2023
NAMESPACE: middleware
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 17.15.1
APP VERSION: 7.0.12

** Please be patient while the chart is being deployed **

Redis® can be accessed via port 6379 on the following DNS name from within your cluster:

    redis-ruoyi-master.middleware.svc.cluster.local

To get your password run:

    export REDIS_PASSWORD=$(kubectl get secret --namespace middleware redis-ruoyi -o jsonpath="{.data.redis-password}" | base64 -d)

To connect to your Redis® server:

1. Run a Redis® pod that you can use as a client:

   kubectl run --namespace middleware redis-client --restart='Never'  --env REDIS_PASSWORD=$REDIS_PASSWORD  --image docker.io/bitnami/redis:7.0.12-debian-11-r19 --command -- sleep infinity

   Use the following command to attach to the pod:

   kubectl exec --tty -i redis-client \
   --namespace middleware -- bash

2. Connect using the Redis® CLI:
   REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-ruoyi-master

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace middleware svc/redis-ruoyi-master 6379:6379 &
    REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379

验证

[root@node1 ~]# export REDIS_PASSWORD=$(kubectl get secret --namespace middleware redis-ruoyi -o jsonpath="{.data.redis-password}" | base64 -d)
[root@node1 ~]# kubectl run --namespace middleware redis-client --restart='Never'  --env REDIS_PASSWORD=$REDIS_PASSWORD  --image docker.io/bitnami/redis:7.0.12-debian-11-r19 --command -- sleep infinity
pod/redis-client created
[root@node1 ~]# 
[root@node1 ~]# kubectl exec --tty -i redis-client \
>    --namespace middleware -- bash
I have no name!@redis-client:/$ REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-ruoyi-master
redis-ruoyi-master:6379> info 
# Server
redis_version:7.0.12
redis_git_sha1:00000000
redis_git_dirty:0

Nacos 安装

官网

clone项目

git clone https://github.com/nacos-group/nacos-k8s.git
#修改Value
Nacos 默认使用NFS来持久化数据,此处更换为openebs的 Storageclass
#修改 nacos-k8s-master/deploy/nacos/nacos-pvc-nfs.yaml

volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ "ReadWriteOnce" ]
        storageClassName: "openebs-data"
        resources:
          requests:
            storage: 20Gi
---  #添加数据库值 
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
data:
  mysql.host: "mysql-ruoyi"
  mysql.db.name: "nacos_ruoyi"
  mysql.port: "3306"
  mysql.user: "nacos"
  mysql.password: "ybyrqedhmydepd"

# 修改镜像版本
# https://hub.docker.com/r/nacos/nacos-server/tags
# image: nacos/nacos-server:v2.2.2
# 使用固定版本

执行数据库脚本

# 此处官网文档没写
https://github.com/alibaba/nacos/blob/master/distribution/conf/mysql-schema.sql

部署

kubectl create -f nacos-k8s/deploy/nacos/nacos-pvc-nfs.yaml

验证

kubectl  -n middleware get pods -l app=nacos
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。