一个spring boot项目迁移到k8s上

  之前写过spring boot项目迁移到k8s,结果昨天用了之前的yaml发现ingress有点问题,现在修复一下重新的yaml如下

---
apiVersion: v1
kind: Service
metadata:
 name: boss-service
 namespace: pre
 labels:
  version: "1.0"
spec:
 # nodePort暴露服务
 type: NodePort
 ports:
  - port: 8080
    protocol: TCP
    targetPort: 8080
    # nodePort: 30411
 selector:
  name: boss
  version: "1.0"

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: boss-ingress
  namespace: pre
spec:
  rules:
  # 访问路径
  - host: pre.boss.com
    http:
      paths:
      - path: /
        backend:
          serviceName: boss-service
          servicePort: 8080
---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: boss
 namespace: pre
 labels:
  version: "1.0"
spec:
 replicas: 1
 # selector:
  # matchExpressions:
  #  - {
  #     key: name, operator: In, values: [boss],
  #     key: version, operator: In, values: ["1.0"]
  #    }
 # 滚动更新策略
 strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
 template:
  metadata:
   labels:
    name: boss
    version: "1.0"
  spec: 
   # serviceAccountName: pre
   # 优雅关闭时间
   terminationGracePeriodSeconds: 30
   containers: 
   - name: boss
     image: springboot-application
     imagePullPolicy: IfNotPresent
     resources:
      requests:
        memory: 1Gi
     livenessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 10
      periodSeconds: 60
     ports:
     - containerPort: 8080
       name: web
       protocol: TCP
     - containerPort: 8181
       name: Heartbeat
       protocol: TCP
     env:
     - name: MYSQL_ROOT_PASSWORD
       value: "password"
     - name: SPRING_PROFILES_ACTIVE
       value: "test"

另外加上mysql的yaml

##namespace
---
#apiVersion: v1
#kind: Namespace
#metadata:
#  name: pre
##mysql-claim.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-ex-claim
  namespace: pre
  annotations:
    volume.beta.kubernetes.io/storage-class: "nfs" 
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 8Gi

##mysql-cm.yaml 
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql-config
  namespace: pre
data:
  custom.cnf: |
        [mysqld]
        server-id=1
        log-bin
        expire_logs_days=7
        sync_binlog=0
        binlog_cache_size=1M

##mysql-secret.yaml
###  echo -n hello |base64
---
apiVersion: v1
kind: Secret
metadata:
  name: mysql-user-pwd
  namespace: pre
data:
  #mysql-root-pwd: NXN0YXI=
  mysql-root-pwd: NXN0YXI=
  #mysql-app-user-pwd: NXN0YXI=
  mysql-app-user-pwd: NXN0YXI=
  #mysql-test-user-pwd: NXN0YXI= 
  mysql-test-user-pwd: NXN0YXI=
##mysql-deployment.yaml
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  namespace: pre
  labels:
    app: mysql-ex
  name: mysql-ex
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql-ex
  template:
     metadata:
       labels:
         app: mysql-ex
     spec:
       initContainers:
       - name: mysql-init
         image: busybox
         imagePullPolicy: IfNotPresent
         env:
         - name: MYSQL_TEST_USER_PASSWORD
           valueFrom:
             secretKeyRef:
               name: mysql-user-pwd
               key: mysql-test-user-pwd
         command:
           - sh
           - "-c"
           - |
             set -ex
             rm -rf /var/lib/mysql/lost+found
             cat > /docker-entrypoint-initdb.d/mysql-boss-initt.sql < /docker-entrypoint-initdb.d/mysql-appdb-init.sql <

rabbitmq的yaml

---
apiVersion: v1
kind: Service
metadata:
  # Expose the management HTTP port on each node
  name: rabbitmq-management
  namespace: pre
  labels:
    app: rabbitmq
spec:
  ports:
  - port: 15672
    name: http
  selector:
    app: rabbitmq
  type: NodePort # Or LoadBalancer in production w/ proper security
---
apiVersion: v1
kind: Service
metadata:
  # The required headless service for StatefulSets
  name: rabbitmq
  namespace: pre
  labels:
    app: rabbitmq
spec:
  ports:
  - port: 5672
    name: amqp
  - port: 4369
    name: epmd
  - port: 25672
    name: rabbitmq-dist
  clusterIP: None
  selector:
    app: rabbitmq
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: rabbitmq
  namespace: pre
spec:
  serviceName: "rabbitmq"
  replicas: 3
  template:
    metadata:
      labels:
        app: rabbitmq
    spec:
      containers:
      - name: rabbitmq
        image: rabbitmq:3.7-rc-management
        lifecycle:
          postStart:
            exec:
              command:
              - /bin/sh
              - -c
              - >
                if [ -z "$(grep rabbitmq /etc/resolv.conf)" ]; then
                  sed "s/^search \([^ ]\+\)/search rabbitmq.\1 \1/" /etc/resolv.conf > /etc/resolv.conf.new;
                  cat /etc/resolv.conf.new > /etc/resolv.conf;
                  rm /etc/resolv.conf.new;
                fi;
                until rabbitmqctl node_health_check; do sleep 1; done;
                if [ -z "$(rabbitmqctl cluster_status | grep rabbitmq-0)" ]; then
                  touch /gotit
                  rabbitmqctl stop_app;
                  rabbitmqctl reset;
                  rabbitmqctl join_cluster rabbit@rabbitmq-0;
                  rabbitmqctl start_app;
                else
                  touch /notget
                fi;
        env:
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: RABBITMQ_ERLANG_COOKIE
          value: "YZSDHWMFSMKEMBDHSGGZ"
        - name: RABBITMQ_NODENAME
          value: "rabbit@$(MY_POD_NAME)"
        ports:
        - containerPort: 5672
          name: amqp

 

你可能感兴趣的:(架构,docker,云计算,mysql,kubernetes,PaaS,k8s)