涉及到的程序:kubernetes,kubersphere,argocd,gitlab,harbor
kubersphere安裝詳見官網(wǎng)
https://kubesphere.io/zh/
kubersphere默認沒有開啟devops词爬,需要修改cluster-configuration.yaml
argocd兩種安裝方式
通過yaml直接執(zhí)行
wget https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
kubectl create namespace argocd
kuberctl apply -f install.yaml
通過helm
helm repo add argo https://argoproj.github.io/argo-helm
helm install argocd --namespace=argocd --create-namespace --set server.service.type=NodePort argo/argo-cd
修改argocd-server為nodeport济蝉,或者使用ingress
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "NodePort"}}'
訪問地址
http://192.168.4.149:32346
默認用戶名admin甜刻,默認密碼 argocd-server的pod名字浩村。如果提示密碼無效拴曲,通過以下方法重置密碼為password
kubectl -n argocd patch secret argocd-secret -p '{"stringData": {"admin.password": "$2a$10$rRyBsGSHK6.uc8fntPwVIuLVHgsAhAX7TcdrqW/RADU0uh7CaChLa","admin.passwordMtime": "'$(date +%FT%T%Z)'"}}'
準備gitlab倉庫缺谴,創(chuàng)建兩個倉庫窗骑,一個放代碼女责,一個放yaml
配置webhook,進入yaml倉庫,安全令牌隨意
修改argocd-secret
kubectl edit secret argocd-secret -n argocd
創(chuàng)建應用
project: default
source:
repoURL: 'http://192.168.4.149:8090/root/argocd-yaml.git'
path: ./
targetRevision: HEAD
destination:
server: 'https://kubernetes.default.svc'
namespace: apps
syncPolicy:
automated:
prune: true
selfHeal: true
syncOptions:
- Validate=false
- CreateNamespace=true
retry:
limit: 3
backoff:
duration: 10s
factor: 2
maxDuration: 5m
在kubersphere中創(chuàng)建devops工程
新建一個devops企業(yè)空間创译,進入企業(yè)空間抵知,創(chuàng)建工程
然后創(chuàng)建流水線
添加憑證(一個gitlab,一個harbor)
編輯流水線
pipeline {
environment {
GIT_URL='http://192.168.4.149:8090/root/argocd-java.git'
GIT_CREDENTIAL_ID = 'gitlab'
GIT_BRANCH = 'master'
REGISTRY = 'docker.plantdata.cn/app/argocd'
REGISTRY_CREDENTIAL_ID = 'harbor'
}
agent {
node {
label 'maven'
}
}
stages {
stage('SCM Checkout') {
steps {
git branch: "${GIT_BRANCH}", credentialsId: "${GIT_CREDENTIAL_ID}", url: "${GIT_URL}"
}
}
stage('source build') {
steps {
container('maven') {
sh 'mvn clean package'
}
}
}
stage('docker build & push') {
steps {
script {
env.COMMIT_ID = sh(returnStdout: true, script: "git log -n 1 --pretty=format:'%h'").trim()
env.TIMESTRAP = sh(returnStdout: true, script: 'date +%Y%m%d%H%M%S').trim()
env.DOCKER_TAG = "dev_${TIMESTRAP}_${COMMIT_ID}_${BUILD_NUMBER}"
}
container('maven') {
withCredentials([usernamePassword(passwordVariable : 'DOCKER_PASSWORD' ,usernameVariable : 'DOCKER_USERNAME' ,credentialsId : "$REGISTRY_CREDENTIAL_ID" ,)]) {
sh 'ls -l'
sh 'docker build -t $REGISTRY:$DOCKER_TAG .'
sh 'echo "$DOCKER_PASSWORD" | docker login $REGISTRY -u "$DOCKER_USERNAME" --password-stdin'
sh 'docker push $REGISTRY:$DOCKER_TAG'
}
}
}
}
stage('update docker tag') {
environment {
BUILD_USER = 'admin'
BUILD_USER_EMAIL = 'admin@argocd.com'
YAML_REPO_URL='http://${username}:${password}@192.168.4.149:8090/root/argocd-yaml.git'
}
steps {
withCredentials([usernamePassword(passwordVariable : 'password' ,usernameVariable : 'username' ,credentialsId : "$GIT_CREDENTIAL_ID" ,)]) {
sh """
git config --global user.name "$BUILD_USER"
git config --global user.email "$BUILD_USER_EMAIL"
git clone ${YAML_REPO_URL} && cd argocd-yaml
sed -i "s#$REGISTRY.*#${REGISTRY}:${DOCKER_TAG}#g" ./deployment.yaml
git add -A && git commit -m "update tag: ${DOCKER_TAG}" && git push ${YAML_REPO_URL}
"""
}
}
}
}
}
點擊運行
查看argocd,已經(jīng)觸發(fā)同步并部署了