K8s 部署 Baget (私有Nuget服务器)

  • 1.Baget介绍

BaGet是一个构建于ASP.NET Core 基础上的 NuGet V3 服务器的开源实现。

  • 2.有哪些Nuget服务器搭建方案

NuGet.Server(Windows平台)、ProGet、MyGet

  • 3.编写yaml文件
  • 3.1 deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: baget
  namespace: default
  labels:
    app: baget
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 2
    type: RollingUpdate
  selector:
    matchLabels:
      app: baget
  template:
    metadata:
      labels:
        app: baget
    spec:     
      containers:
      - name: baget
        image: loicsharma/baget:latest
        ports:
        - containerPort: 80
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 250m
            memory: 256Mi
        livenessProbe:
          httpGet:
            path: /v3/index.json
            port: 80
          initialDelaySeconds: 30
          timeoutSeconds: 30
          successThreshold: 1
          failureThreshold: 3
          periodSeconds: 30
        env:
        - name: PATH
          value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
        - name: ASPNETCORE_URLS
          value: http://+:80
        - name: DOTNET_RUNNING_IN_CONTAINER
          value: "true"
        - name: ApiKey
          value: afe0f754-68b0-38a1-b7bf-44a34263465d
        - name: Storage__Type
          value: FileSystem
        - name: Storage__Path
          value: /var/baget/packages
        - name: Database__Type
          value: Sqlite
        - name: Database__ConnectionString
          value: Data Source=/var/baget/baget.db
        - name: Search__Type
          value: Database
        - name: AllowPackageOverwrites
          value: "true"
        volumeMounts:
        - name: baget-data
          mountPath: /var/baget
      volumes:
      - name: baget-data
        persistentVolumeClaim:
          claimName: baget
  • 3.2 pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: baget
  namespace: default
spec:
  storageClassName: sc-nfs-hdd
  resources:
    requests:
      storage: 50Gi        #设置 pvc 存储资源大小
  accessModes:
  - ReadWriteOnce
  • 3.3 service.yaml
apiVersion: v1
kind: Service
metadata:
  name: baget
  namespace: default
  labels:
    app: baget
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: baget
  • 3.4 ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: baget
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: baget.navywang.top
    http:
      paths:
      - path: /
        backend:
          serviceName: baget
          servicePort: 80

 

 

kc apply -f /home/k8s/yaml/baget

 访问:http://baget.navywang.top:xxxx

  • 4 打包

 点击项目配置作者、版本号信息

打包

 查看生成nupkg文件

 在该目录执行

dotnet nuget push -s http://baget.navywang.top:xxx/v3/index.json Navy.DB.1.0.0.nupkg -k afe0f754-68b0-38a1-b7bf-44a34263465d
dotnet nuget push -s http://baget.navywang.top:xxx/v3/index.json Navy.DB.1.0.1.nupkg -k afe0f754-68b0-38a1-b7bf-44a34263465d

-k:api秘钥

-s:Nuget服务器url

访问http://baget.navywang.top:xxx

 

  •  5 使用私有Nuget包

 

  • 6 删除某个版本的包
dotnet nuget delete -s http://baget.navywang.top:xxx/v3/index.json Navy.DB 1.0.1 -k afe0f754-68b0-38a1-b7bf-44a34263465d

 

posted @ 2024-01-31 18:48  NavyW  阅读(83)  评论(0编辑  收藏  举报