
yaml
apiVersion: v1
kind: Pod
spec:
volumes:
- name: certs-ca
emptyDir: {}
- name: certs-client
emptyDir: {}
containers:
- name: dind
image: docker:24.0-dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: /certs
volumeMounts:
- name: certs-ca
mountPath: /certs/ca
- name: certs-client
mountPath: /certs/client
tty: true
- name: docker
image: docker:24.0
command:
- cat
tty: true
env:
- name: DOCKER_TLS_CERTDIR
value: /certs
- name: DOCKER_HOST
value: tcp://localhost:2376
- name: DOCKER_TLS_VERIFY
value: "1"
- name: DOCKER_CERT_PATH
value: /certs/client
volumeMounts:
- name: certs-client
mountPath: /certs/client
readOnly: true
- name: kubectl
image: alpine/kubectl:1.34.2
command:
- cat
tty: true
最后pipeline
js
pipeline {
environment {
image ="hub.da9893.com/k8s/$JOB_NAME:$BUILD_ID"
}
agent {
kubernetes {
inheritFrom 'docker'
}
}
stages {
stage('Get Code') {
steps {
checkout scmGit(branches: [[name: '*/v10.1.3']], extensions: [], userRemoteConfigs: [[credentialsId: 'ltd', url: 'http://WW.GITHUB/robot-weit']]) }
}
stage('Docker Build Push') {
steps {
container('docker') {
sh 'docker info'
sh 'ps aux | grep docker'
//script {
// withDockerRegistry(credentialsId: 'hub', url: 'https://hub.da9893.com') {
// def builtImage = docker.build("${image}", ".")
// builtImage.push()
//}
//sh "docker rmi ${image} || true"
// }
}
}
}
stage('Deloy SIT') {
steps {
container('kubectl') {
withKubeConfig(credentialsId: '16-k8s', serverUrl: 'https://192.168.12.16:6443') {
sh 'kubectl get pods -A'
}
}
}
}
}
}