使用GitHub/Jenkins/Kubernetes实现CI/CD管道时的最佳实践
这个问题与建议更相关,所以我希望它没有任何意义。只是真的需要帮助:( 尝试使用GitHub/Jenkins/Kubernetes实现CI/CD 从高层次上讲,这是应该发生的:使用GitHub/Jenkins/Kubernetes实现CI/CD管道时的最佳实践,jenkins,kubernetes,continuous-integration,continuous-deployment,Jenkins,Kubernetes,Continuous Integration,Continuous Deployment,这个问题与建议更相关,所以我希望它没有任何意义。只是真的需要帮助:( 尝试使用GitHub/Jenkins/Kubernetes实现CI/CD 从高层次上讲,这是应该发生的: 以詹金斯为基础 推送到容器注册表 在Kubernetes开发集群上部署构建映像 在开发集群上完成测试后,将其部署到客户机上 测试集群,最后是生产集群 到目前为止,这就是我在Jenkins上创建的作业,它将使用Github钩子触发。 该工作负责以下事项: 从GitHub签出 运行单元测试/调用RESTAPI并发送单元测试结果
非常感谢我知道您正在尝试实现GitOps,我的建议是查看本文,在这里您可以开始了解更多有关所需组件的信息
基本上,您需要为您的定制服务实现自己的掌舵图,并使用flux进行管理。我建议每个环境使用不同的存储库,并让flux根据repo上主分支的状态管理每个环境的部署。我知道您正试图实现GitOps,我的建议是是回顾这篇文章,在这里您可以开始了解更多关于所需组件的信息
基本上,您需要为自定义服务实现自己的helm图表,并使用flux进行管理。我建议在每个环境中使用不同的存储库,让flux根据repo上主分支的状态来管理每个环境的部署。有无数种方法可以做到这一点。现在请将helm作为你才刚刚开始 如果您已经在使用Github和docker,那么我建议您将代码/更改/配置/Dockerfile推送到Github,这将自动触发Dockerhub上的docker构建(如果您不想使用Dockerhub进行构建,可能是jenkins),它可以是一个多阶段docker构建,您可以在其中构建代码、运行测试、丢弃开发环境,并最终生成一个producion docker映像。一旦生成映像,它将触发一个web钩子,指向kubernetes部署作业/清单,部署到测试evironmenet,然后手动triiger部署到生产环境 docker映像可以基于Github/Git中提交的SHA进行标记,以便您可以基于提交进行部署和回滚 参考: 以下是我的Gtips工作流的Gitlab实现:
# Author , IjazAhmad
image: docker:latest
stages:
- build
- test
- deploy
services:
- docker:dind
variables:
CI_REGISTRY: dockerhub.example.com
CI_REGISTRY_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH
DOCKER_DRIVER: overlay2
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
docker-build:
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:latest .
docker-push:
stage: build
script:
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
unit-tests:
stage: test
script:
- echo "running unit testson the image"
- echo "running security testing on the image"
- echo "pushing the results to build/test pipeline dashboard"
sast:
stage: test
script:
- echo "running security testing on the image"
- echo "pushing the results to build/test pipeline dashboard"
dast:
stage: test
script:
- echo "running security testing on the image"
- echo "pushing the results to build/test pipeline dashboard"
testing:
stage: deploy
script:
- sed -i "s|CI_IMAGE|$CI_REGISTRY_IMAGE|g" k8s-configs/deployment.yaml
- sed -i "s|TAG|$CI_COMMIT_SHA|g" k8s-configs/deployment.yaml
- kubectl apply --namespace webproduction-test -f k8s-configs/
environment:
name: testing
url: https://testing.example.com
only:
- branches
staging:
stage: deploy
script:
- sed -i "s|CI_IMAGE|$CI_REGISTRY_IMAGE|g" k8s-configs/deployment.yaml
- sed -i "s|TAG|$CI_COMMIT_SHA|g" k8s-configs/deployment.yaml
- kubectl apply --namespace webproduction-stage -f k8s-configs/
environment:
name: staging
url: https://staging.example.com
only:
- master
production:
stage: deploy
script:
- sed -i "s|CI_IMAGE|$CI_REGISTRY_IMAGE|g" k8s-configs/deployment.yaml
- sed -i "s|TAG|$CI_COMMIT_SHA|g" k8s-configs/deployment.yaml
- kubectl apply --namespace webproduction-prod -f k8s-configs/
environment:
name: production
url: https://production.example.com
when: manual
only:
- master
链接:
有无数种方法可以做到这一点。在你刚刚开始的时候,现在就把头盔拿出来 如果您已经在使用Github和docker,那么我建议您将代码/更改/配置/Dockerfile推送到Github,这将自动触发Dockerhub上的docker构建(如果您不想使用Dockerhub进行构建,可能是jenkins),它可以是一个多阶段docker构建,您可以在其中构建代码、运行测试、丢弃开发环境,并最终生成一个producion docker映像。一旦生成映像,它将触发一个web钩子,指向kubernetes部署作业/清单,部署到测试evironmenet,然后手动triiger部署到生产环境 docker映像可以基于Github/Git中提交的SHA进行标记,以便您可以基于提交进行部署和回滚 参考: 以下是我的Gtips工作流的Gitlab实现:
# Author , IjazAhmad
image: docker:latest
stages:
- build
- test
- deploy
services:
- docker:dind
variables:
CI_REGISTRY: dockerhub.example.com
CI_REGISTRY_IMAGE: $CI_REGISTRY/$CI_PROJECT_PATH
DOCKER_DRIVER: overlay2
before_script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
docker-build:
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:latest .
docker-push:
stage: build
script:
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
unit-tests:
stage: test
script:
- echo "running unit testson the image"
- echo "running security testing on the image"
- echo "pushing the results to build/test pipeline dashboard"
sast:
stage: test
script:
- echo "running security testing on the image"
- echo "pushing the results to build/test pipeline dashboard"
dast:
stage: test
script:
- echo "running security testing on the image"
- echo "pushing the results to build/test pipeline dashboard"
testing:
stage: deploy
script:
- sed -i "s|CI_IMAGE|$CI_REGISTRY_IMAGE|g" k8s-configs/deployment.yaml
- sed -i "s|TAG|$CI_COMMIT_SHA|g" k8s-configs/deployment.yaml
- kubectl apply --namespace webproduction-test -f k8s-configs/
environment:
name: testing
url: https://testing.example.com
only:
- branches
staging:
stage: deploy
script:
- sed -i "s|CI_IMAGE|$CI_REGISTRY_IMAGE|g" k8s-configs/deployment.yaml
- sed -i "s|TAG|$CI_COMMIT_SHA|g" k8s-configs/deployment.yaml
- kubectl apply --namespace webproduction-stage -f k8s-configs/
environment:
name: staging
url: https://staging.example.com
only:
- master
production:
stage: deploy
script:
- sed -i "s|CI_IMAGE|$CI_REGISTRY_IMAGE|g" k8s-configs/deployment.yaml
- sed -i "s|TAG|$CI_COMMIT_SHA|g" k8s-configs/deployment.yaml
- kubectl apply --namespace webproduction-prod -f k8s-configs/
environment:
name: production
url: https://production.example.com
when: manual
only:
- master
链接:
查看spinnaker以实现连续交付。在构建映像并将其推送到注册表后,让spinnaker中的web钩子触发到所需kubernetes群集的部署。spinnaker与kubernetes配合得很好,您肯定应该试用它。查看spinnaker以实现连续交付。在构建映像并将其推送到注册表后istry,在spinnaker中设置一个web钩子,触发对所需kubernetes群集的部署。spinnaker与kubernetes配合良好,您肯定应该尝试使用它通常使用webhook术语。例如,您可以配置dockerhub在新图像标记到达时触发jenkins作业,jenkins作业将部署到kubernetes。或者您可以从github获取jenkins作业,使用github API,jenkins将构建映像,将其推送到注册表并触发下游作业,该作业将新映像部署到Kubernete。有无数的排列:)是的,有多种方法可以再次执行,妈妈