Your Name 9 months ago
commit e11d6cb612
  1. 6
      Dockerfile
  2. 39
      Jenkinsfile
  3. 1
      index.html
  4. 20
      k8s/deploy.yml

@ -0,0 +1,6 @@
FROM daocloud.io/library/nginx
WORKDIR /usr/share/nginx/html
COPY . ./
CMD ["nginx","-g","daemon off;"]
EXPOSE 80

39
Jenkinsfile vendored

@ -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…
Cancel
Save