首页 > 其他分享 >k8s部署单机版nacos

k8s部署单机版nacos

时间:2023-07-28 18:34:37浏览次数:37  
标签:单机版 name nacos value mysql k8s spec metadata

来源:

https://www.jianshu.com/p/4f69d1b369d1

mysql

安装mysql如下:

  • 创建mysql.yml文件如下:
[root@DoM01 nacos]# cat mysql.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: mysql
  namespace: nacos
  labels:
    name: mysql
spec:
  replicas: 1
  selector:
    name: mysql
  template:
    metadata:
      labels:
        name: mysql
    spec:
      containers:
      - name: mysql
        image: nacos/nacos-mysql:5.7
        ports:
        - containerPort: 3306
        volumeMounts:
        - name: nacos-mysql
          mountPath: /var/lib/mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "40010355"
        - name: MYSQL_DATABASE
          value: "nacos"
        - name: MYSQL_USER
          value: "nacos"
        - name: MYSQL_PASSWORD
          value: "40010300"
        - name: TZ
          value: Asia/Shanghai
      volumes:
      - name: nacos-mysql
        persistentVolumeClaim:
          claimName: nacos-mysql-pvc
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: nacos-mysql-pvc
  namespace: nacos
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 20Gi
  storageClassName: nfs-client
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: nacos
  labels:
    name: mysql
spec:
  ports:
  - port: 3306
    targetPort: 3306
  selector:
    name: mysql
  • 启动
#kubectl create -f mysql.yml
  • 查看结果
root@DoM01 nacos]# kubectl get pod -n nacos
NAME          READY   STATUS    RESTARTS   AGE
mysql-lckvh   1/1     Running   0          40h

[root@DoM01 nacos]# kubectl get service -n nacos
NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                         AGE
mysql            ClusterIP   10.1.189.109   <none>        3306/TCP                        40h

nacos-standalone

  • 创建nacos-stand.yaml文件如下
---
apiVersion: v1
kind: Service
metadata:
  name: nacos
  namespace: nacos
  labels:
    app: nacos
spec:
  type: NodePort
  ports:
    - port: 8848
      name: server
      targetPort: 8848
      nodePort: 30018
    - port: 7848
      name: rpc
      targetPort: 7848
      nodePort: 30019
  selector:
    app: nacos
---
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  namespace: nacos
  labels:
    app: nacos
spec:
  ports:
    - port: 8848
      name: server
      targetPort: 8848
    - port: 7848
      name: rpc
      targetPort: 7848
  clusterIP: None
  selector:
    app: nacos
---
# 链接mysql数据库
apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-cm
  namespace: nacos
data:
  mysql.db.name: "nacos"
  mysql.port: "3306"
  mysql.user: "nacos"
  mysql.password: "40010355"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
  namespace: nacos
spec:
  serviceName: nacos-headless
  replicas: 1
  template:
    metadata:
      labels:
        app: nacos
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - nacos
              topologyKey: "kubernetes.io/hostname"
      containers:
        - name: nacos
          imagePullPolicy: Always
          image: nacos/nacos-server:latest
          resources:
            requests:
              memory: "2Gi"
              cpu: "500m"
          ports:
            - containerPort: 8848
              name: client-port
            - containerPort: 7848
              name: rpc
          env:
            - name: NACOS_REPLICAS
              value: "1"
            - name: MYSQL_SERVICE_DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.db.name
            - name: MYSQL_SERVICE_PORT
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.port
            - name: MYSQL_SERVICE_USER
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.user
            - name: MYSQL_SERVICE_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: nacos-cm
                  key: mysql.password
            - name: NACOS_SERVER_PORT
              value: "8848"
            - name: NACOS_APPLICATION_PORT
              value: "8848"
            - name: PREFER_HOST_MODE
              value: "hostname"
            - name: TZ
              value: Asia/Shanghai
            - name: MODE
              value: standalone
          volumeMounts:
            - name: datadir
              mountPath: /home/nacos/data
            - name: logdir
              mountPath: /home/nacos/logs
  volumeClaimTemplates:
    - metadata:
        name: datadir
        annotations:
          volume.beta.kubernetes.io/storage-class: "nfs-client"
      spec:
        accessModes: [ "ReadWriteMany" ]
        resources:
          requests:
            storage: 10Gi
    - metadata:
        name: logdir
        annotations:
          volume.beta.kubernetes.io/storage-class: "nfs-client"
      spec:
        accessModes: [ "ReadWriteMany" ]
        resources:
          requests:
            storage: 10Gi
  selector:
    matchLabels:
      app: nacos
  • 启动
#kubectl create -f nacos-stand.yaml


作者:开发运维玄德公
链接:https://www.jianshu.com/p/4f69d1b369d1
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

标签:单机版,name,nacos,value,mysql,k8s,spec,metadata
From: https://www.cnblogs.com/gaoyanbing/p/17588648.html

相关文章

  • 最全springcloudAlibaba视频笔记-第三章Nacos Config服务配置中心
    NacosConfig服务配置中心课程视频:https://www.bilibili.com/video/BV1VW4y1o7n5本课程使用的是目前最新版本2022.0.0.0-RC2。基于SpringBoot3.0与JDK20的开发环境。集群中每一台主机的配置文件都是相同的,对配置文件的更新维护就成为了一个棘手的问题。此时就出现了配置中心......
  • 数据源为postgresSQL的docker版nacos
    1.首先编写Dcokerfile,基础镜像为ubuntu:18.04,安装Java环境等FROMubuntu:18.04ENVJAVA_DIR=/usr/localENVJAVA_HOME=$JAVA_DIR/java8ENVPATH=$PATH:$JAVA_HOME/binENVNACOS_VERSION=2.2.0.1ENVNACOS_HOME=/nacos#安装jdkCOPY./jdk-8u11-linux-x64.tar.gz$JAVA......
  • MicroK8s 引起的 kubadm init 失败,端口占用
    前言今天在ubuntu20上安装k8s集群,前面的步骤都完成了,结果在kubeadminit的时候出现了下面的问题。errorexecutionphasepreflight:[preflight]Somefatalerrorsoccurred:[ERRORPort-10259]:Port10259isinuse[ERRORPort-10257]:Port10257isi......
  • 最后的组合:K8s 1.24 基于 Hekiti 实现 GlusterFS 动态存储管理实践
    前言知识点定级:入门级GlusterFS和Heketi简介GlusterFS安装部署Heketi安装部署Kubernetes命令行对接GlusterFS实战服务器配置(架构1:1复刻小规模生产环境,配置略有不同)主机名IPCPU内存系统盘数据盘用途ks-master-0192.168.9.912450100KubeS......
  • k8s 按照文档
    一、环境准备两台服务器:1、master2、worker-node3、关闭防火墙:systemctlstopfirewalldsystemctldisablefirewalld4、关闭selinuxsed-i's/enforcing/disabled/'/etc/selinux/configsetenforce05、关闭swapswapoff-ased-ri's/.*swap.*/#&/'/etc/fstab6、服务器规划cat......
  • 创建k8s 镜像仓库登录密钥
    原标题:k8s使用私有镜像仓库的访问凭据配置k8s创建私有仓库凭据有两种方式1.使用kubectl命令创建secret2.使用docker凭证作为k8s的凭据。文章来源地址https://www.yii666.com/blog/458024.html1.使用kubectl命令创建secretkubectlcreatesecretdocker-registry<name>--do......
  • k8s数据卷 Volume 之 hostPath 与 emptyDir
    一、为什么需要volume(数据卷)?容器中的文件在磁盘上是临时存放的,这给容器中运行比较重要的应用程序带来一些问题。问题1:当容器升级或者崩溃时,kubelet会重建容器,容器内文件会丢失问题2:一个Pod中运行多个容器需要共享文件。Kubernetes卷(Volume)这一抽象概念能够解决这两个问题......
  • BC-Linux for Euler部署K8S-1.27
    目录1、介绍及说明1.1主机信息1.2部署组件及规划2、基础优化2.1开启ipv62.2修改文件最大数2.3配置hosts解析2.4内核参数优化2.5selinux关闭2.6防火墙2.7ipvs支持2.8内核版本要求2.9yum源配置3、部署3.1docker及cri-docker安装及配置-所有主机3.1.1docker3.1.2cri-......
  • k8s中如何固定一个pod的IP地址?该集群网络插件是calico
    1、首先查看calico的CIDR地址范围[root@nccztsjb-node-17~]#calicoctlgetippoolNAMECIDRSELECTORdefault-pool172.23.0.0/16all() 2、然后呢,在这个地址范围内,给pod选择一个固定的IP地址比如:172.23.45.27 通过在pod中加入annotat......
  • k8s 部署dashboard 2.7.0
    查看dashboard版本兼容性Kubernetesversion1.221.231.241.25Compatibility???✓准备dashboardyaml文件#wgethttps://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml准备image#dockerpulldocker.io/kubernete......