赞
踩
具体步骤:
微服务架构图
拉取仓库代码
git clone http://192.168.0.126/saas-wms/linkinsense-wms-public.git
编译代码
mvn clean package -Dmaven.test.skip=true -Pdev
编写gateway服务的DockerFile,制作镜像
vi Dockerfile
FROM openjdk:8-jre
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN echo 'Asia/Shanghai' > /etc/timezone
WORKDIR /wms-center/wms-gateway
ADD ./target/wms-gateway-1.0.0.jar ./
EXPOSE 8901
CMD java -jar wms-gateway-1.0.0.jar
docker build -t wms-gateway:v1 -f wms-gateway/Dockerfile ./wms-gateway/
docker images
之前本地部署的镜像仓库Harbor: http://192.168.0.127:8084/
,如果没有可拿docker-hub注册一个账号。
登录仓库
docker login 192.168.0.127:8084
docker tag wms-gateway:v1 192.168.0.127:8084/onlee/gateway:v1
docker push 192.168.0.127:8084/onlee/gateway:v1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: gateway
namespace: wms-dev
spec:
replicas: 1
selector:
matchLabels:
project: wms-dev
app: gateway
template:
metadata:
labels:
project: wms-dev
app: gateway
spec:
imagePullSecrets:
- name: registry-harbor
containers:
- name: gateway
image: 192.168.0.127:8084/onlee/gateway:v1
imagePullPolicy: Always
ports:
- protocol: TCP
containerPort: 8901
env:
- name: JAVA_OPTS
value: "-Xmx1g"
resources:
requests:
cpu: 0.5
memory: 256Mi
limits:
cpu: 1
memory: 1Gi
readinessProbe:
tcpSocket:
port: 8901
initialDelaySeconds: 60
periodSeconds: 10
livenessProbe:
tcpSocket:
port: 8901
initialDelaySeconds: 60
periodSeconds: 10
kubectl create namespace wms-dev
kubectl apply -f gateway.yaml
FROM nginx
COPY dist /usr/share/nginx/html/
EXPOSE 80
docker build -t wms-web:v1 -f Dockerfile .
docker tag wms-web:v1 192.168.0.127:8084/onlee/wms-web:v1
docker push 192.168.0.127:8084/onlee/wms-web:v1
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: wms-web
name: wms-web
namespace: wms-dev
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
app: wms-web
strategy:
rollingUpdate:
maxSurge: 50%
maxUnavailable: 50%
type: RollingUpdate
template:
metadata:
labels:
app: wms-web
spec:
imagePullSecrets:
- name: registry-harbor
containers:
- image: 192.168.0.127:8084/onlee/wms-web:v1
imagePullPolicy: Always
name: app
ports:
- containerPort: 80
protocol: TCP
resources:
limits:
cpu: 300m
memory: 600Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
kubectl apply -f web.yaml
通过整个微服务架构可知,只有gateway和前端需要暴露服务。
gateway对外暴露
---
apiVersion: v1
kind: Service
metadata:
name: gateway
namespace: wms-dev
spec:
ports:
- port: 8901
name: gateway
protocol: TCP
targetPort: 8901
nodePort: 32074
selector:
project: wms
app: gateway
type: NodePort
前端对外暴露
---
apiVersion: v1
kind: Service
metadata:
labels:
app: wms-web
name: wms-web
namespace: wms-dev
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
nodePort: 32248
selector:
app: wms-web
sessionAffinity: None
type: NodePort
gateway对外暴露
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: gateway
namespace: wms-dev
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
spec:
rules:
- host: gateway.wms.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: gateway
port:
number: 8901
---
apiVersion: v1
kind: Service
metadata:
name: gateway
namespace: wms-dev
spec:
ports:
- port: 8901
name: gateway
selector:
project: wms-dev
app: gateway
前端对外暴露
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: wms-web
namespace: wms-dev
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/backend-protocol: "HTTP"
spec:
rules:
- host: dev.wms.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: wms-web
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
labels:
app: wms-web
name: wms-web
namespace: wms-dev
spec:
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
selector:
app: wms-web
sessionAffinity: None
你知道的越多,你不知道的越多。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。