準(zhǔn)備dockerfile和jenkinsfile還有yml文件
因?yàn)槲仪叭綄⑵渌亩寂昧?,我現(xiàn)在的目的只是為了簡單部署上去,所以沒做其他深入研究配置,我的簡單代碼:https://gitee.com/feiminjie/helloworldfront
我準(zhǔn)備的dockerfile
# 使用官方 Node.js 鏡像
FROM node:14
# 設(shè)置工作目錄
WORKDIR /appf
# 將項(xiàng)目文件復(fù)制到容器中
COPY . .
# 安裝項(xiàng)目依賴
RUN npm install
# 構(gòu)建生產(chǎn)環(huán)境
RUN npm run build
# 暴露端口
EXPOSE 80
# 啟動(dòng)應(yīng)用
CMD ["npm", "run", "start"]
我準(zhǔn)備的Jenkinsfile
// 所有的腳本命令都放在當(dāng)前的pipline中
pipeline{
// 制定任務(wù)在哪個(gè)集群節(jié)點(diǎn)中執(zhí)行
agent any
// 聲明全局變量,方便后面使用
environment {
key = 'value'
}
stages {
stage('拉取git倉庫代碼') {
steps {
checkout scmGit(branches: [[name: '${tag}']], extensions: [], userRemoteConfigs: [[credentialsId: 'ee882b26-32f7-487f-af8b-8ce97ae6d923', url: 'https://gitee.com/feiminjie/helloworldfront.git']])
}
}
stage('生成docker鏡像') {
steps {
sh 'docker build -t hellofront:$tag .'
}
}
stage('推送harbor') {
steps {
sh '''docker login -u admin -p Harbor12345 103.39.222.98:80
docker tag hellofront:$tag 103.39.222.98:80/hellofront/hellofront:$tag
docker push 103.39.222.98:80/hellofront/hellofront:$tag'''
}
}
stage('推送yml到master') {
steps {
sshPublisher(publishers: [sshPublisherDesc(configName: 'k8s', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: 'pipefront.yml')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
stage('執(zhí)行yml文件') {
steps {
sh '''ssh root@103.39.226.71 kubectl apply -f /usr/local/k8s/pipefront.yml
ssh root@103.39.226.71 kubectl rollout restart deployment helloworldfront-deployment -n front'''
}
}
}
}
里面配置和后端寫的區(qū)分開就行了
我準(zhǔn)備的 front.yml
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: front
name: helloworldfront-deployment
labels:
app: helloworldfront-deployment
spec:
replicas: 2
selector:
matchLabels:
app: helloworldfront
template:
metadata:
labels:
app: helloworldfront
spec:
containers:
- name: helloworldfront
image: 103.39.222.98:80/hellofront/hellofront:v4.0.0
imagePullPolicy: Always
ports:
- containerPort: 80
imagePullSecrets:
- name: harbor-token
---
apiVersion: v1
kind: Service
metadata:
namespace: front
name: helloworldfront-deployment
labels:
app: helloworldfront-deployment
spec:
selector:
app: helloworldfront
ports:
- port: 80
targetPort: 80
type: NodePort
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
labels:
app: helloworldfront-deployment
k8s.kuboard.cn/name: helloworldfront-deployment
name: helloworldfront-deployment
namespace: front
spec:
defaultBackend:
service:
name: helloworldfront-deployment
port:
number: 80
ingressClassName: ingress
rules:
- host: bomj.shop
http:
paths:
- backend:
service:
name: helloworldfront-deployment
port:
number: 80
path: /
pathType: Prefix
kuboard配置
1、創(chuàng)建上面yml文件中的命名空間
2、在front命名空間內(nèi)創(chuàng)建密文
步驟都和前面三步中的步驟差不多,如果有什么報(bào)錯(cuò)對著日志改一改就可以了。
任意節(jié)點(diǎn)+端口就可以訪問了文章來源:http://www.zghlxwxcb.cn/news/detail-841571.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-841571.html
到了這里,關(guān)于【四】將vue部署到k8s中的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!