Skip to content

Latest commit

 

History

History

nodejs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

通过 调用k8s 接口 直接 部署 服务

  • 通过 web 界面 上传 镜像 到服务 器
  • 将镜像推送到 registry 镜像仓库
  • 通过 k8s 接口部署服务
  • 通过 k8s 接口暴露服务

安装依赖

npm install express @kubernetes/client-node

启动服务

node app.js

测试部署 API

curl -X POST http://localhost:3000/deploy \
-H "Content-Type: application/json" \
-d '{"imageName": "nginx:latest", "containerPort": 80}'

返回的json结果

{
  "deploymentName": "app-1698598100000-deployment",
  "serviceName": "app-1698598100000-service",
  "servicePort": 32345,
  "nodeIp": "192.168.1.100",
  "message": "Service 'app-1698598100000-service' is exposed on node '192.168.1.100:32345'"
}

安装 harbor 镜像仓库

helm repo add harbor https://helm.goharbor.io
helm repo update
helm install harbor harbor/harbor --namespace harbor --set expose.type=nodePort --set expose.tls.enabled=false --set persistence.enabled=true
helm install harbor harbor/harbor --namespace harbor --set expose.type=nodePort --set expose.hostname=192.168.110.116 --set expose.tls.enabled=false --set persistence.enabled=true

helm install harbor harbor/harbor --namespace harbor \
  --set expose.type=nodePort \
  --set expose.hostname=192.168.110.116 \
  --set expose.tls.enabled=false \
  --set persistence.enabled=true

helm uninstall -n harbor harbor harbor/harbor
kubectl get pods -n harbor
kubectl get svc -n harbor

harbo 帐号:admin 密码:Harbor12345

harbor 如果麻烦,请使用 docker 官方的部署 registry

使用

docker tag io3d-server:latest 192.168.110.116:30500/vendor/io3d-server:latest
docker push 192.168.110.116:30500/vendor/io3d-server:latest

查看镜像仓库中的镜像

curl -i 192.168.110.116:30500/v2/_catalog

通过 调用k8s 接口 直接 部署 服务

curl -X POST http://localhost:3000/deploy \
-H "Content-Type: application/json" \
-d '{"imageName": "192.168.110.116:30500/vendor/io3d-server:latest", "containerPort": 8100}'

修改k8s 配置文件

sudo vi /etc/containerd/config.toml

#####
[plugins."io.containerd.grpc.v1.cri".registry]
  [plugins."io.containerd.grpc.v1.cri".registry.mirrors]
    [plugins."io.containerd.grpc.v1.cri".registry.mirrors."192.168.110.116:30500"]
      endpoint = ["http://192.168.110.116:30500"]
#####

sudo systemctl restart containerd
apiVersion: apps/v1
kind: Deployment
metadata:
  name: image-pull-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: image-pull-test
  template:
    metadata:
      labels:
        app: image-pull-test
    spec:
      containers:
        - name: test-container
          image: 192.168.110.116:30500/my-image:latest  # 你的私有镜像地址
          imagePullPolicy: Always