From e11d6cb61289649d83682c20ec463fc3f002d543 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 17 Dec 2023 18:41:15 +0800 Subject: [PATCH] a --- Dockerfile | 6 ++++++ Jenkinsfile | 39 +++++++++++++++++++++++++++++++++++++++ index.html | 1 + k8s/deploy.yml | 20 ++++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 index.html create mode 100644 k8s/deploy.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f14d63c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM daocloud.io/library/nginx +WORKDIR /usr/share/nginx/html +COPY . ./ +CMD ["nginx","-g","daemon off;"] +EXPOSE 80 + diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..20240b8 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,39 @@ +pipeline { + agent any + + environment { + DOCKER_IMAGE = "my-web-app:latest" + K8S_DEPLOYMENT_NAME = "my-web-app-deployment" + } + + stages { + stage('Build Docker Image') { + steps { + script { + docker.build("${DOCKER_IMAGE}") + } + } + } + stage('Push to Registry') { + steps { + script { + // 假设已经配置了 Docker 认证 + docker.withRegistry('https://registry.example.com', 'registry-credentials') { + docker.image("${DOCKER_IMAGE}").push() + } + } + } + } + stage('Deploy to Kubernetes') { + steps { + script { + kubernetesDeploy( + configs: 'k8s/deployment.yaml', + kubeconfigId: 'K8S_CLUSTER_CONFIG' + ) + } + } + } + } +} + diff --git a/index.html b/index.html new file mode 100644 index 0000000..c52d936 --- /dev/null +++ b/index.html @@ -0,0 +1 @@ +hello k8s diff --git a/k8s/deploy.yml b/k8s/deploy.yml new file mode 100644 index 0000000..a085587 --- /dev/null +++ b/k8s/deploy.yml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-web-app-deployment +spec: + replicas: 2 + selector: + matchLabels: + app: my-web-app + template: + metadata: + labels: + app: my-web-app + spec: + containers: + - name: my-web-app + image: core.harbor.cn:30210/my-web-app:latest + ports: + - containerPort: 8080 +