해당 글은 일프로 님의 인프런 강의 쿠버네티스 어나더 클래스 (지상편) - Sprint 1, 2의 내용을 정리한 글입니다.
해당 글에 사용된 내용, 사진 및 그림은 모두 강의와 강의 자료에 포함된 내용입니다.
https://192.168.56.30:30002/login
kubectl get -n argo secret argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d
## Server
server:
service:
type: NodePort
nodePortHttps: 30002
pipeline {
agent any
parameters {
choice(choices: ['option', 'namespace_create', 'namespace_delete', 'helm_upgrade', 'helm_uninstall'], name: 'DEPLOY_TYPE', description: '배포 타입 선택')
choice(choices: ['option', 'argo-cd', 'argocd-image-updater', 'argo-rollouts'], name: 'TARGET_ARGO', description: 'Argo 대상 선택')
}
environment {
DOCKERHUB_USERNAME = '1pro'
GITHUB_URL = 'https://github.com/k8s-1pro/install.git'
INSTALL_PATH = 'ground/cicd-server/argo'
}
stages {
stage('네임스페이스 관리') {
steps {
script{
if (params.DEPLOY_TYPE == "namespace_create") {
withCredentials([file(credentialsId: 'k8s_master_config', variable: 'KUBECONFIG')]) {
sh "kubectl apply -f ./${INSTALL_PATH}/kubectl/namespace.yaml --kubeconfig " + '${KUBECONFIG}'
}
} else if (params.DEPLOY_TYPE == "namespace_delete") {
withCredentials([file(credentialsId: 'k8s_master_config', variable: 'KUBECONFIG')]) {
sh "kubectl delete -f ./${INSTALL_PATH}/kubectl/namespace.yaml --kubeconfig " + '${KUBECONFIG}'
}
} else {
echo "skip namespace"
}
}
}
}
stage('헬름 배포 관리') {
steps {
script{
if (params.DEPLOY_TYPE == "helm_upgrade") {
withCredentials([file(credentialsId: 'k8s_master_config', variable: 'KUBECONFIG')]) {
HELM_DEPLOY_COMMAND = "helm upgrade ${params.TARGET_ARGO} ./${INSTALL_PATH}/helm/${params.TARGET_ARGO} " +
" -f ./${INSTALL_PATH}/helm/${params.TARGET_ARGO}/values-mac.yaml" +
" -n argo --install --kubeconfig " + '${KUBECONFIG}' +
" --wait --timeout=10m " // 최대 10분으로 설정
// image-updater일 경우 도커허브 credentials 주입
if (params.TARGET_ARGO == "argocd-image-updater") {
// https://argocd-image-updater.readthedocs.io/en/stable/basics/update-methods/
withCredentials([usernamePassword(credentialsId: 'docker_password', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
HELM_DEPLOY_COMMAND += " --set config.registries[0].credentials=env:DOCKER_HUB_CREDS="+ '${USERNAME}' + ":" + '${PASSWORD}'
}
}
sh "eval ${HELM_DEPLOY_COMMAND}"
// sh "helm update argo-cd -n argo --kubeconfig " + '${KUBECONFIG}' + " --wait --timeout=10m "
}
} else if (params.DEPLOY_TYPE == "helm_uninstall") {
withCredentials([file(credentialsId: 'k8s_master_config', variable: 'KUBECONFIG')]) {
sh "helm uninstall ${params.TARGET_ARGO} -n argo --kubeconfig " + '${KUBECONFIG}'
// CRD 삭제
if (params.TARGET_ARGO == "argo-cd") {
sh "kubectl delete crd applications.argoproj.io applicationsets.argoproj.io appprojects.argoproj.io --kubeconfig " + '${KUBECONFIG}'
}
if (params.TARGET_ARGO == "argo-rollouts") {
sh "kubectl delete crd analysisruns.argoproj.io analysistemplates.argoproj.io clusteranalysistemplates.argoproj.io --kubeconfig " + '${KUBECONFIG}'
sh "kubectl delete crd experiments.argoproj.io rollouts.argoproj.io --kubeconfig " + '${KUBECONFIG}'
}
}
} else {
echo "skip deploy"
}
}
}
}
}
}
while true; do curl http://192.168.56.30:32233/version; sleep 2; echo ''; done;
while true; do curl http://192.168.56.30:32243/version; sleep 2; echo ''; done;
http://192.168.56.30:30003/rollouts/anotherclass-223
curl -LO https://github.com/argoproj/argo-rollouts/releases/download/v1.6.4/kubectl-argo-rollouts-linux-amd64
chmod +x ./kubectl-argo-rollouts-linux-amd64
mv ./kubectl-argo-rollouts-linux-amd64 /usr/local/bin/kubectl-argo-rollouts
kubectl argo rollouts version
kubectl argo rollouts get rollout api-tester-2233 -n anotherclass-223 -w
kubectl apply -f https://raw.githubusercontent.com/k8s-1pro/kubernetes-anotherclass-sprint2/main/2234/deploy/argo-rollouts/rollout.yaml -n anotherclass-223
kubectl apply -f https://raw.githubusercontent.com/k8s-1pro/kubernetes-anotherclass-sprint2/main/2234/deploy/argo-rollouts/configmap.yaml -n anotherclass-223
kubectl apply -f https://raw.githubusercontent.com/k8s-1pro/kubernetes-anotherclass-sprint2/main/2234/deploy/argo-rollouts/secret.yaml -n anotherclass-223
kubectl apply -f https://raw.githubusercontent.com/k8s-1pro/kubernetes-anotherclass-sprint2/main/2234/deploy/argo-rollouts/service.yaml -n anotherclass-223
kubectl argo rollouts get rollout api-tester-2234 -n anotherclass-223 -w
while true; do curl http://192.168.56.30:32234/version; sleep 2; echo ''; done;
kubectl argo rollouts set image api-tester-2234 api-tester-2234=1pro/api-tester:2.0.0 -n anotherclass-223