印章
2021/03/13
醫療環境導入 GitOps
印章 (seal.tw ),不是海豹
本名 吳易璋
「前」某醫學中心打雜
兼任 On-Permise Cloud 架構師
兼任 Infra 維運
兼任 SRE
賭神從來不拍照
印章 (seal.tw ),不是海豹
本名 吳易璋
社群打雜:
Gitlab Taiwan
Cloud Native Taiwan User Group
https://argoproj.github.io/argo-cd/
https://www.weave.works/technologies/gitops/
The entire system described declaratively(聲明式).
The canonical desired system state versioned in Git.
Approved changes that can be automatically applied to the system.
Software agents to ensure correctness and alert on divergence.
https://www.weave.works/technologies/gitops/
https://about.gitlab.com/topics/gitops/
https://commons.wikimedia.org/wiki/File:Agile-vs-iterative-flow.jpg
http://www.globalnerdy.com/2007/11/28/dilbert-on-extreme-and-agile-programming/
https://about.gitlab.com/topics/gitops/
傳統環境 (VM/Bare Metal):
Ansible
http://note.drx.tw/2017/08/continuous-delivery-with-ansible-x-gitlab-ci.html
Chef (GitLab Omnibus)
Puppet
Terraform
容器化 (Container) :
Docker compose
Kubernetes
https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/
https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/
https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/
https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/
https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/
https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/
todo: runner、running dashboard
build:
image: node:14-alpine
stage: build
script:
- apk update
- yarn install --production=false
- npx ng build \
--env=prod \
--base-href ./ \
--progress=false \
--verbose
artifacts:
paths:
- dist
- package.json
expire_in: 1 hour
FROM node:alpine AS base
WORKDIR /webapi
FROM node:alpine AS build
WORKDIR /webapi
RUN apk update
COPY . /webapi
RUN yarn install
FROM base
COPY --from=build /webapi /webapi
CMD /usr/local/bin/node dist/main.js 3000
todo: pipeline
$ docker run -d --rm \
--name=gitlab-runner \
--restart=always \
-v $PWD/config.toml:/etc/gitlab/config.toml \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:alpine-v13.9.0
$ docker exec -it gitlab-runner register
# podman? I don't know, how to?
docker_build:
image: docker:1903-dind
stage: docker_build
variables:
IMAGE: registry.example.io/
${CI_PROJECT_NAME}:${CI_COMMIT_SHORT_SHA}
#example: quay.io/example-image:v1.0
script:
- docker login -u myusername -p mypassword
- docker build . -t $IMAGE
- docker push $IMAGE
dependencies:
- build
review_docker:
image: docker:1903-dind
stage: review
variables:
IMAGE: registry.example.io/
${CI_PROJECT_NAME}:${CI_COMMIT_SHORT_SHA}
#example: quay.io/example-image:v1.0
script:
- docker rm -f ${CI_PROJECT_NAME}
- docker run -d --rm \
--name=${CI_PROJECT_NAME} \
--restart=always \
${IMAGE}
tags:
- testing
deploy_compose:
image: rockwyc992/docker-compose:latest
stage: deploy
variables:
IMAGE: registry.example.io/
${CI_PROJECT_NAME}:${CI_COMMIT_SHORT_SHA}
#example: quay.io/example-image:v1.0
script:
- envsubst \
< docker-compose.template.yml \
> docker-compose.yml
- docker-compose up -d
only:
- master
tags:
- production
Kubernetes is an open source system for managing Container across multiple hosts.
Kubernetes is an open source system for managing Container across multiple hosts.
apiVersion: apps/v1
kind: Deployment
metadata:
name: gitlab-runner
namespace: gitlab
spec:
template:
spec:
containers:
image: gitlab/gitlab-runner:alpine-v13.9.0
volumeMounts:
- mountPath: /etc/gitlab-runner
name: config
serviceAccountName: runner
volumes:
- configMap:
name: gitlab-runner
name: config
replicas: 1
concurrent = 10
[[runners]]
name = "Kubernetes Runner"
url = "https://gitlab.example.com"
token = "__REDACTED__"
executor = "kubernetes"
[runners.kubernetes]
#host = "http://localhost:9876/"
image = "alpine:3.12"
namespace = "gitlab"
privileged = false
service_account_overwrite_allowed = "runner"
[runners.kubernetes.volumes]
[[runners.kubernetes.volumes.host_path]]
name = "docker"
mount_path = "/var/run/docker.sock"
apiVersion: v1
kind: ServiceAccount
metadata:
name: runner
namespace: gitlab
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: runner
namespace: gitlab
subjects:
- kind: ServiceAccount
name: runner
namespace: gitlab
roleRef:
kind: ClusterRole
name: admin
apiGroup: rbac.authorization.k8s.io
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: gitlab-runner
namespace: mynamespace
subjects:
- kind: ServiceAccount
name: runner
namespace: gitlab
roleRef:
kind: ClusterRole
name: admin
apiGroup: rbac.authorization.k8s.io
.kubectl_template:
image: lachlanevenson/k8s-kubectl:v1.19.8
stage: deploy
variables:
NAMESPACE: default
script:
- envsubst \
< deployment.template.yaml \
> deployment.yaml
- envsubst \
< service.template.yaml \
> service.yaml
- kubectl -n $NAMESPACE apply -f deployment.yaml
- kubectl -n $NAMESPACE apply -f service.yaml
tags:
- kubernetes
review_kubectl:
extends: .kubectl_template
stage: review
variables:
NAMESPACE: gitlabops-review
staging_kubectl:
extends: .kubectl_template
stage: staging
variables:
NAMESPACE: gitlabops-staging
only:
- master
deploy_kubectl:
extends: .kubectl_template
stage: deploy
variables:
NAMESPACE: gitlabops-production
when: manual
only:
- master
GitLab Cloud Native Chart
https://docs.gitlab.com/charts/
GitLab Kubernetes Agent
https://docs.gitlab.com/ee/user/clusters/agent/
Code of Conduct 行爲準則
請參考 https://about.gitlab.com/company/culture/contribute/coc/