Kubernetes Cloud Native 实践 ( 五 ) 应用上云

2023-06-13 20:53:40 459

全文目录

Kubernetes Cloud Native 实践 ( 一 ) 安装

Kubernetes Cloud Native 实践 ( 二 ) 简单使用

Kubernetes Cloud Native 实践 ( 三 ) NFS/PV/PVC

Kubernetes Cloud Native 实践 ( 四 ) 中间件上云

Kubernetes Cloud Native 实践 ( 五 ) 应用上云

Kubernetes Cloud Native 实践 ( 六 ) 集成ELK日志平台

Kubernetes Cloud Native 实践 ( 七 ) 应用监控

Kubernetes Cloud Native 实践 ( 八 ) CICD集成

Kubernetes Cloud Native 实践 ( 九 ) 运维管理

Kubernetes Cloud Native 实践 ( 十 ) 相关问题

Kubernetes Cloud Native 实践 ( 十一 ) 运行截图


  1. 应用上云
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"labels":{"app.kubernetes.io/instance":"app","app.kubernetes.io/name":"app"},"name":"app"}}
  labels:
    app.kubernetes.io/instance: app
    app.kubernetes.io/name: app
  name: app
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"StatefulSet","metadata":{"annotations":{},"name":"user-api","namespace":"app"}}
  name: user-api
  namespace: app
spec:
  replicas: 1
  serviceName: user-api
  selector:
    matchLabels:
      app: user-api
  template:
    metadata:
      name: user-api-pod
      labels:
        app: user-api
    spec:
      imagePullSecrets:
      - name: aliyun-docker
      containers:
        - name: user-api-container
          image: registry.cn-hangzhou.aliyuncs.com/thy-k8s/user-api:latest
          resources:
            limits:
              memory: "520Mi"
              cpu: "200m"
          ports:
            - containerPort: 8001
          env:
            - name: JAVA_OPTS
              value: "-javaagent:/home/java/skywalking-agent/skywalking-agent.jar -Xms256m -Xmx512m"
            - name: APP_OPTS
              value: >
                -Dspring.profiles.active=prod 
                -Dspring.cloud.nacos.discovery.server-addr=nacos-headless.nacos 
                -Dspring.cloud.nacos.discovery.namespace=19a0fa32-ed2e-40f1-a1e1-aae8c81d8cf8 
                -Dskywalking.agent.service_name=user-api 
                -Dskywalking.collector.backend_service=skywalking-oap.skywalking-oap:11800
          volumeMounts:
            - name: log
              mountPath: "/data/logs/user-api/"
  volumeClaimTemplates:
  - metadata:
      name: log
      annotations:
        volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 1Gi    
---
apiVersion: v1
kind: Service
metadata:
  name: user-api
  namespace: app
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"name":"user-api","namespace":"app"}}
spec:
  type: NodePort
  selector:
    app: user-api
  ports:
    - name: http
      protocol: TCP
      nodePort: 30088
      port: 80
      targetPort: 8001

  1. user-web
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"labels":{"app.kubernetes.io/instance":"app","app.kubernetes.io/name":"app"},"name":"app"}}
  labels:
    app.kubernetes.io/instance: app
    app.kubernetes.io/name: app
  name: app
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"StatefulSet","metadata":{"annotations":{},"name":"user-web","namespace":"app"}}
  name: user-web
  namespace: app
spec:
  replicas: 1
  serviceName: user-web
  selector:
    matchLabels:
      app: user-web
  template:
    metadata:
      name: user-web-pod
      labels:
        app: user-web
    spec:
      imagePullSecrets:
      - name: aliyun-docker
      containers:
        - name: user-web-container
          image: registry.cn-hangzhou.aliyuncs.com/thy-k8s/user-web:latest
          resources:
            limits:
              memory: "520Mi"
              cpu: "200m"
          ports:
            - containerPort: 9001
          env:
            - name: JAVA_OPTS
              value: "-javaagent:/home/java/skywalking-agent/skywalking-agent.jar -Xms256m -Xmx512m"
            - name: APP_OPTS
              value: >
                -Dspring.profiles.active=prod 
                -Dspring.cloud.nacos.discovery.server-addr=nacos-headless.nacos 
                -Dspring.cloud.nacos.discovery.namespace=19a0fa32-ed2e-40f1-a1e1-aae8c81d8cf8 
                -Dskywalking.agent.service_name=user-web 
                -Dskywalking.collector.backend_service=skywalking-oap.skywalking-oap:11800
          volumeMounts:
            - name: log
              mountPath: "/data/logs/user-web/"
  volumeClaimTemplates:
  - metadata:
      name: log
      annotations:
        volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 1Gi    
---
apiVersion: v1
kind: Service
metadata:
  name: user-web
  namespace: app
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"name":"user-web","namespace":"app"}}
spec:
  type: NodePort
  selector:
    app: user-web
  ports:
    - name: http
      protocol: TCP
      nodePort: 30188
      port: 80
      targetPort: 9001

  1. record-web
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Namespace","metadata":{"annotations":{},"labels":{"app.kubernetes.io/instance":"app","app.kubernetes.io/name":"app"},"name":"app"}}
  labels:
    app.kubernetes.io/instance: app
    app.kubernetes.io/name: app
  name: app
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"StatefulSet","metadata":{"annotations":{},"name":"record-web","namespace":"app"}}
  name: record-web
  namespace: app
spec:
  replicas: 1
  serviceName: record-web
  selector:
    matchLabels:
      app: record-web
  template:
    metadata:
      name: record-web-pod
      labels:
        app: record-web
    spec:
      imagePullSecrets:
      - name: aliyun-docker
      containers:
        - name: record-web-container
          image: registry.cn-hangzhou.aliyuncs.com/thy-k8s/record-web:latest
          resources:
            limits:
              memory: "520Mi"
              cpu: "200m"
          ports:
            - containerPort: 9002
          env:
            - name: JAVA_OPTS
              value: "-javaagent:/home/java/skywalking-agent/skywalking-agent.jar -Xms256m -Xmx512m"
            - name: APP_OPTS
              value: >
                -Dspring.profiles.active=prod 
                -Dspring.cloud.nacos.discovery.server-addr=nacos-headless.nacos 
                -Dspring.cloud.nacos.discovery.namespace=19a0fa32-ed2e-40f1-a1e1-aae8c81d8cf8 
                -Dskywalking.agent.service_name=record-web 
                -Dskywalking.collector.backend_service=skywalking-oap.skywalking-oap:11800
          volumeMounts:
            - name: log
              mountPath: "/data/logs/record-web/"
  volumeClaimTemplates:
  - metadata:
      name: log
      annotations:
        volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
    spec:
      accessModes: ["ReadWriteOnce"]
      resources:
        requests:
          storage: 1Gi    
---
apiVersion: v1
kind: Service
metadata:
  name: record-web
  namespace: app
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"name":"record-web","namespace":"app"}}
spec:
  type: NodePort
  selector:
    app: record-web
  ports:
    - name: http
      protocol: TCP
      nodePort: 30288
      port: 80
      targetPort: 9002


Java操作Redis的常见误区

不能使用 keys * 命令不能在set中存放大量数据
2021-01-11

Java 单例模式

双重校验懒汉式单例public class Singleton { //1. 避免jvm指令重排 由于JVM具有指令重排的特性,执行顺序有可能变成 1-3-2。指令重排在单线程下不会出现问题,但是在多线程下会导致一个线程获得一个未初始化的实例。例如:线程T1执行了1和3,此时T2调用 ge
2021-01-06

Java 工厂模式

public class Rectangle implements Shape { @Override public void draw() { System.out.println("Inside Rectangle::draw() method."); } }
2021-01-02

Java 模板模式

public abstract class Template { public final void templ() { System.out.println("开始"); code(); System.out.println("结束"); } public abstract v
2021-01-02

Java 装饰者模式

接口Printerpublic interface Printer { void start(); void print(); void stop(); } 实现类 HPPrinter public class HPPrinter implements Printer {
2021-01-02
Java Proxy.newProxyInstance动态代理

Java Proxy.newProxyInstance动态代理

定义接口public interface Student { void buy(); String talk(); } 实现类public class Lisi implements Student { @Override public void buy() { System.ou
2021-01-02

Java 解析windows 快捷方式 lnk文件

转载自 https://www.oschina.net/code/snippet_12_274import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; public c
2020-12-10

Spring Boot项目中使用RedisTemplate.delete() 删除指定key失败的解决办法

https://blog.csdn.net/hello_world_qwp/article/details/85763286上面这篇博客扯一大堆, 居然还分析源码实际只是自定义了key的序列化方式导致最终操作redis的时候序列化的key与预期的key不一致而已, 自然就删不掉redis中的数据了
2020-11-26

jpa方法参数必须加上@Param

void deleteByKl(String kl);线上可能报错原因可能是编译时没有加-parameters这个参数, 编译后丢失了参数名称, 使得反射拿不到对应参数需要加上注解void deleteByKl(@Param("kl") String kl);同理public ResultVO de
2020-09-28

日志规范

日志中要打印参数错误示例 @GetMapping("/share_coupon") public ActionResult shareCoupon(Long couponSn) { //validate code try { retur
2020-09-17

Java中的Date和时区转换

1.Date中保存的是什么在java中,只要我们执行 Date date = new Date(); 就可以得到当前时间。如:Date date = new Date(); System.out.println(date); 输出结果是: Thu Aug 24 10:15:29 CST 2017 也
2020-03-28
基于自定义注解手写权限控制

基于自定义注解手写权限控制

方法一: AOP 方法二: 拦截器项目结构项目依赖<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-w
2020-03-28

如何在Java中替换多个if语句

1. 概述选择结构是任何编程语言的重要组成部分。但是我们编写了大量嵌套的if语句,这使得我们的代码更加复杂和难以维护。 在本教程中,我们将介绍替换嵌套if语句的各种方法。 让我们探索如何简化代码的不同选项。2. 案例研究我们经常遇到涉及很多条件的业务逻辑,并且每个都需要不同的处理。为了演示,我们以C
2020-03-28
Java中方法的参数传递机制

Java中方法的参数传递机制

来看一段代码 public class Man { private String name; private Integer age; public String getName() { return name; } publi
2020-03-28

freemarker 时间显示不正常 设置时区

项目在本地开发的时候显示正常,部署上服务器就一直差8个小时,最后发现freemarker官方文档有这样的说明time_zone:时区的名称来显示并格式化时间。 默认情况下,使用JVM的时区。 也可以是 Java 时区 API 接受的值,或者 "JVM default" (从 FreeMarker 2
2020-03-28
IDEA 2019.1 xml 不高亮

IDEA 2019.1 xml 不高亮

前几天更新了idea后,发现xml里的代码都没有了高亮,变得跟记事本一个德性了打开setting ,搜索 File Types,找到xml项, 查看下方的匹配格式,果然没有xml,(idea真是厉害)点击右方的+,输入*.xml,点击ok,解决问题
2020-03-28

npm install 淘宝镜像

npm install --registry=https://registry.npm.taobao.org
2020-03-28
Java中方法的参数传递机制

Java中方法的参数传递机制

来看一段代码 public class Man { private String name; private Integer age; public String getName() { return name; } publi
2020-03-28
基于自定义注解手写权限控制

基于自定义注解手写权限控制

方法一: AOP 方法二: 拦截器项目结构项目依赖<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-w
2020-03-28

Docker 部署 详细全过程 附代码

Docker 部署本站 全过程环境:CentOS7.61. 安装Docker其他版本CentOS可以参考这个https://help.aliyun.com/document_detail/187598.html查看本机内核版本,内核版本需高于 3.10uname -r 确保 yum 包最新yum u
2020-03-28

SpringBoot 启动普通java工程

引入依赖<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <version>2.0.9</version> </dependency>
2020-03-28

Vue.js DOM操作

<template> <input type="button" @click="reply($event)" value="回复"> </template> export default { methods: { replyFun(e) {
2020-03-29
CentOS7编译调试OpenJDK12

CentOS7编译调试OpenJDK12

1. 下载源码https://hg.openjdk.java.net/jdk/jdk12点击左侧的browse,再点击zip,就可以下载zip格式的源码压缩包。unzip xxx.zip 解压文件2. 安装jdkyum install java-11-openjdk-devel -y3. 运行con
2020-04-23
编写自己的Spring Boot Starter

编写自己的Spring Boot Starter

1.新建一个maven项目命名规则统一是xxx-spring-boot-starter完整pom.xml<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0"
2020-06-29