실습3. 프로젝트 생성 및 테스트

깃랩에 프로젝트를 커밋하기 위해 다음 과정을 거친다.

다음과 같이 프로젝트를 깃랩에 생성 및 코드 반영

1
2
3
4
5
6
7
git config --global user.name "sangheonKim"
git config --global user.email "tkdgjs1501@nate.com"

git init
git remote add origin http://35.200.116.34/sangheonKim/sangheonProject.git
git commit -m "init"
git push origin master

커밋하는데 아래와 같은 에러가 뜰 경우 레파지토리 이름에 .git를 넣었는지 확인해보자.

1
2
3
4

error: RPC failed; result=22, HTTP code = 404
fatal: The remote end hung up unexpectedly

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
def label = "master"

def notifyStarted() {
slackSend (color: '#FFFF00', message: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}

def notifySuccessful() {
slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}

def notifyFailed() {
slackSend (color: '#FF0000', message: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}

podTemplate(label: label,
containers: [
containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'docker', image: 'docker:stable', ttyEnabled: true, command: 'cat'),
containerTemplate(name: 'kubectl', image: 'lachlanevenson/k8s-kubectl:v1.8.0', command: 'cat', ttyEnabled: true)
],
volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
hostPathVolume(hostPath: '/root/.m2', mountPath: '/root/.m2')
]

) {

node(label) {
try {


stage('Get Source') {
git "http://35.200.116.34/sangheonKim/sangheonProject"
}

def props = readProperties file:'deployment/pipeline.properties'
/*def tag = VersionNumber (versionNumberString: '${BUILD_DATE_FORMATTED, "yyyyMMdd"}-develop-${BUILDS_TODAY}')*/
def tag = props['version']
def gitSrc = props['gitSrc']
def dockerRegistry = props['dockerRegistry']
def image = props['image']
def deployment = props['deployment']
def service = props['service']
def selector = props['selector']
def namespace = props['namespace']


stage('Build Maven project') {
container('maven') {
sh "mvn -B clean package"
}
}
/*
stage('Inspection Code') {
container('maven') {
sh "mvn sonar:sonar \
-Dsonar.projectKey=sangheon \
-Dsonar.host.url=http://34.85.31.212:9000 \
-Dsonar.login=62cf8d43f8fda31db0c5682c71b584c8650f4509"
}
}
*/
stage('Build Docker image') {
container('docker') {
docker.withRegistry("${dockerRegistry}", 'registry-credentials') {
sh "docker build -t ${image}:${tag} ."
sh "docker push ${image}:${tag}"
sh "docker tag ${image}:${tag} ${image}:latest"
sh "docker push ${image}:latest"
}
}
}

stage( 'Clean Up Existing Deployments' ) {
container('kubectl') {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'registry-credentials',
usernameVariable: 'DOCKER_HUB_USER',
passwordVariable: 'DOCKER_HUB_PASSWORD']]) {

sh "kubectl delete deployments -n ${namespace} --selector=app=${selector}"
}
}
}

stage( 'Deploy to Cluster' ) {
container('kubectl') {
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'registry-credentials',
usernameVariable: 'DOCKER_HUB_USER',
passwordVariable: 'DOCKER_HUB_PASSWORD']]) {

sh "kubectl apply -n ${namespace} -f ${deployment}"
sh "sleep 5"
sh "kubectl apply -n ${namespace} -f ${service}"
}
}
}

notifySuccessful()
} catch(e) {
print(e)
currentBuild.result = "FAILED"
notifyFailed()
}

}
}

1
2
3
4
5
6
7
8
version=0.1.0
cluster=devcluster.icp
namespace=default
dockerRegistry=http://docker-registry.default.svc.cluster.local:5000
image=http://docker-registry.default.svc.cluster.local:5000/default/masterapi
deployment=deployment/masterapi-deploy.yaml
service=deployment/masterapi-svc.yaml
selector=masterapi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: masterapi-sangheonkim
spec:
replicas: 3
template:
metadata:
labels:
app: masterapi-sangheonkim
spec:
containers:
- name: masterapi-sangheonkim
image: http://docker-registry.default.svc.cluster.local:5000/default/masterapi
imagePullPolicy: Always
ports:
- containerPort: 8280

다음 그림처럼 파이프라인을 생성하자

kubectl create clusterrolebinding default-binding –clusterrole=cluster-admin –user=admin –user=kubelet –group=system:serviceaccounts:default

1
2
3
4
5
6
7
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
Waiting for next available executor

위와 같은 오류가 뜬다면

Share