kubernetes

Kubernetes部署应用服务

2022-06-19  本文已影响0人  想成为大师的学徒小纪

承接上文Kubernetes高可用部署,本文介绍应用程序服务部署到k8s平台步骤流程

一、安装网络文件系统(NFS)

此处为单机版安装,不具备高可用冗余性能

二、helm安装高可用harbor镜像仓库

1、安装外部postgresql数据库

2、创建PV和PVC

3、helm安装harbor

三、Docker配置使用harbor

四、构建镜像上传私库

五、使用k8s集群部署服务

1、创建服务运行命名空间

kubectl create ns apps
cat > /data/k8s/install/podpreset.yaml <<'EOF'
apiVersion: settings.k8s.io/v1alpha1
kind: PodPreset
metadata:
  name: tz-env
  namespace: apps
spec:
  selector:
    matchLabels:
  env:
    - name: TZ
      value: Asia/Shanghai
EOF
kubectl apply -f /data/k8s/install/podpreset.yaml

2、创建harbor仓库身份验证的secret

先使用docker login命令登录harbor,保存有授权令牌的config.json文件,再执行以下命令

kubectl create secret generic harbor-login \
    --from-file=.dockerconfigjson=/root/.docker/config.json \
    --type=kubernetes.io/dockerconfigjson -n apps

3、创建deployment资源

fbu-fps-task-worker-test_deployment.yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    field.cattle.io/description: Export Billing Services
  labels:
    business: fbu
    environment: test
    service: fps-task-worker
    system: fps
    tier: backend
  name: fbu-fps-task-worker-test
  namespace: apps
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      service: fps-task-worker
    matchExpressions:
    - key: environment
      operator: In
      values: [test]
    - key: business
      operator: In
      values: [fbu]
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        business: fbu
        environment: test
        service: fps-task-worker
        system: fps
        tier: backend
    spec:
      containers:
      - env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: ENVS
          value: test
        - name: Xmx
          value: 2048m
        name: fbu-fps-task-worker
        image: harbor.eminxing.com/fbu-fps-task-worker/fbu-fps-task-worker:v1.0.0
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 5
          periodSeconds: 1
          successThreshold: 1
          tcpSocket:
            port: 9102
          timeoutSeconds: 1
        ports:
        - containerPort: 9102
          name: web
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /health
            port: 9102
            scheme: HTTP
          initialDelaySeconds: 2
          periodSeconds: 2
          successThreshold: 1
          timeoutSeconds: 2
        resources:
          limits:
            cpu: "2"
            memory: 3Gi
          requests:
            cpu: 500m
            memory: 1Gi
        startupProbe:
          failureThreshold: 3
          httpGet:
            path: /health
            port: 9102
            scheme: HTTP
          initialDelaySeconds: 45
          periodSeconds: 2
          successThreshold: 1
          timeoutSeconds: 2
        volumeMounts:
        - mountPath: /opt/logs/fps-task-worker
          name: logs
          subPathExpr: $(POD_NAME)
      dnsConfig:
        options:
        - name: ndots
          value: "2"
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: harbor-login
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      volumes:
      - hostPath:
          path: /opt/logs/fps-task-worker
          type: DirectoryOrCreate
        name: logs

4、创建service资源

fbu-fps-task-worker-test_service.yaml文件

apiVersion: v1
kind: Service
metadata:
  name: fbu-fps-task-worker-test
  annotations:
    field.cattle.io/description: Export Billing Services
  labels:
    business: fbu
    environment: test
    service: fps-task-worker
    system: fps
    tier: backend
  namespace: apps
spec:
  selector:
    business: fbu
    environment: test
    service: fps-task-worker
  type: ClusterIP
  ports:
    - name: web
      port: 9102
      protocol: TCP
      targetPort: 9102
  sessionAffinity: None

5、创建ingress资源

上一篇下一篇

猜你喜欢

热点阅读