K8s部署Nexus3

01/02 08:11
阅读数 1.6K

K8S nexus3.yaml文件

kind: Service
apiVersion: v1
metadata:
  name: qian-nexus3
  namespace: default
  labels:
    app: qian-nexus3
spec:
  type: NodePort
  selector:
    app: qian-nexus3
  ports:
  #服务端口,内部端口,通过暴露端口登录的最终会转到内部
    - port: 8081
      name: rest
      targetPort: 8081
      protocol: TCP
      #登录平台暴露的端口
      nodePort: 31234
  #服务端口,内部端口
    - port: 8087
      name: rest1
      targetPort: 8087
      protocol: TCP
      #docker login暴露的端口
      nodePort: 31235
---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: qian-nexus3
  namespace: default
spec:
  replicas: 1
  minReadySeconds: 120
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1 
      maxUnavailable: 1 
  selector:
    matchLabels:
      app: qian-nexus3
  template:
    metadata:
      labels:
        app: qian-nexus3
    spec:
      containers:
      - name: qian-nexus3
        image: sonatype/nexus3:latest
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 1024m
            memory: 2048Mi
          requests:
            cpu: 50m
            memory: 200Mi
        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 180
          periodSeconds: 10
          successThreshold: 1
          tcpSocket:
            port: 8081
          timeoutSeconds: 2
        ports:
        - containerPort: 8081
          name: rest
          protocol: TCP
        - containerPort: 8087
          name: rest1
          protocol: TCP
        volumeMounts:
        - mountPath: /nexus-data
          name: dev
        securityContext:
          privileged: true
      dnsPolicy: ClusterFirst
      nodeName: node-2
      volumes:
      - hostPath:
          path: /srv/nexus/qian-data
        name: dev

镜像源服务器操作:

mkdir -p  /srv/nexus/qian-data
chmod 777 /srv/nexus/qian-data
chown 200 /srv/nexus/qian-data

master管理服务器操作:

kubectl apply -f nexus3.yaml.yaml

注释:

    - containerPort: 8087    ##容器端口
      name: rest1
      protocol: TCP
-----------------------------------
    - port: 8087         ##容器端口
      name: rest1
      targetPort: 8087   
      protocol: TCP
      nodePort: 31235     ##集群外部访问Service,Pod提供访问接入端口,仅在type为NodePort时才需要指定.

访问nexus3

http://192.168.123.12:31234
登录用户admin
密码看提示路径,进入路径后文件中则为密码

设置私有仓库步骤:

1、设置
2、Repositories
3、Create repository
4、docker(hosted)

继上一步配置步骤docker(hosted)

1、Name                              (自定义名称)
2、http   8087                       (勾选http,填写内部上传端口)
3、Docker Registry API Support       (勾选 Allow clients to use the V1 API to interact with this repository)
4、Create repository                  (创建)

测试本地推镜像(哪台需要dockers login哪台就配置)

vi /lib/systemd/system/docker.service
修改为:镜像源ip和上传端口
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock   --insecure-registry=192.168.123.12:31235
sudo systemctl daemon-reload
sudo systemctl restart docker
docker login IP:31234
用户名:
密码:

docker打标签:

sudo docker tag  300e315adb2f  192.168.123.12:31235/nginx:v5.6
docker login IP:8087
账号
密码

docker push   192.168.123.12:31235/nginx:v5.6
docker pull   192.168.123.12:31235/nginx:v5.6

注意:当使用yaml调用nexus私有仓库镜像时,需要进行Docker registries认证才能push不然无法使用
kubectl create secret docker-registry regsecret --docker-server=192.168.123.12:8087 --docker-username=admin --docker-password=12345 --docker-email=admin@ctsi.com.cn --namespace=default

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部