main
commit
e11d6cb612
@ -0,0 +1,6 @@ |
||||
FROM daocloud.io/library/nginx |
||||
WORKDIR /usr/share/nginx/html |
||||
COPY . ./ |
||||
CMD ["nginx","-g","daemon off;"] |
||||
EXPOSE 80 |
||||
|
@ -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' |
||||
) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1 @@ |
||||
hello k8s |
@ -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 |
||||
|
Loading…
Reference in new issue