GunSik2 / k8s-ai

ai/bigdata/gpu examples with k8s
0 stars 0 forks source link

GitOps #30

Open GunSik2 opened 2 years ago

GunSik2 commented 2 years ago

GitOps

GitOps 개발자 환경

참고자료

GunSik2 commented 2 years ago

GitOps Quick Start

설치

curl -L "https://github.com/weaveworks/weave-gitops/releases/download/v0.3.0/gitops-$(uname)-$(uname -m)" -o gitops
chmod +x gitops
sudo mv ./gitops /usr/local/bin/gitops
gitops version

$ gitops install
$ kubectl get pods --namespace wego-system
NAME                                           READY   STATUS    RESTARTS   AGE
helm-controller-b5c45677f-zz6r7                1/1     Running   0          80s
image-automation-controller-57f8bf65c7-km8qn   1/1     Running   0          80s
image-reflector-controller-558c56b989-nnsbw    1/1     Running   0          80s
kustomize-controller-7fd4d6b4c8-jwbks          1/1     Running   0          80s
notification-controller-66545867f4-bsmqk       1/1     Running   0          80s
source-controller-5d469c75b6-vtjqf             1/1     Running   0          80s

GitHub에서 예시용 레퍼지토리 Fork

GitOps 시험

  1. GitOps 앱 등록
    
    $ git clone https://github.com/GunSik2/podinfo-deploy
    $ cd podinfo-deploy/
    $ ◎ Checking cluster status
    ✔ GitOps installed
    ⚠️ Setting the "GITHUB_TOKEN" environment variable to a valid token will allow ongoing use of the CLI without requiring a browser-based auth flow...

Visit this URL to authenticate with Github:

https://github.com/login/device

Type the following code into the page at the URL above: 735C-2CC2

Waiting for authentication flow completion...

Authentication successful!

Existing deploy key found Adding application:

Name: podinfo-deploy URL: ssh://git@github.com/GunSik2/podinfo-deploy.git Path: ./ Branch: main Type: kustomize

✚ Generating Source manifest ✚ Generating GitOps automation manifests ✚ Generating Application spec manifest ► Cloning ssh://git@github.com/GunSik2/podinfo-deploy.git Pull Request created: https://github.com/GunSik2/podinfo-deploy/pull/1

► Applying manifests to the cluster ► Committing and pushing gitops updates for application ✔ App is up to date

2. 중간에 Github 접속하여 인증 필요: https://github.com/login/device
![image](https://user-images.githubusercontent.com/11453229/135553089-0efe2f85-e9c1-4edb-86c3-90830e5c3c1a.png)

3. GitOps Pull Request 확인
![image](https://user-images.githubusercontent.com/11453229/135554836-bbf87246-f98a-414a-8474-145f5fd83641.png)

4. GitOps Pull Request 승인
![image](https://user-images.githubusercontent.com/11453229/135554890-220cc691-3dae-4b62-b497-535f0b46eef8.png)

5. App 배포 확인

$ kubectl get pod -n test NAME READY STATUS RESTARTS AGE backend-6597979bbf-njhtr 1/1 Running 0 2m frontend-745f795d57-dgbwx 1/1 Running 0 2m

$ gitops app status podinfo-deploy NAME READY MESSAGE REVISION SUSPENDED gitrepository/podinfo-deploy True Fetched revision: main/dfd72488c9be9ee52fd0726ba7e118dd7d84e48d main/dfd72488c9be9ee52fd0726ba7e118dd7d84e48d False

NAME READY MESSAGE REVISION SUSPENDED kustomization/podinfo-deploy True Applied revision: main/dfd72488c9be9ee52fd0726ba7e118dd7d84e48d main/dfd72488c9be9ee52fd0726ba7e118dd7d84e48d False

// 초기 배포 시 자동 생성된 파일 $ git pull $ tree .wego/ .wego/ ├── apps │   └── podinfo-deploy │   └── app.yaml └── targets └── local └── podinfo-deploy ├── podinfo-deploy-gitops-deploy.yaml └── podinfo-deploy-gitops-source.yaml

// Ingress 배포 (k8s v1.18은 ingress CLI 배포 미 지원) // $ kubectl create ingress podinfo --rule="podinfo.test.14.xx.xx.xx.xip.io/*=frontend:9898" -n test $ vi ingress.yml

apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: podinfo namespace: test spec: rules:

  1. Git 업데이트
    
    $ vi frontend/deployment.yaml
        env:
        - name: PODINFO_UI_COLOR
          value: "#888888"
    $ git add .
    $ git commit -m "change color"
    $ git push

// 자동 배포 확인 $ kubectl get pods --namespace test NAME READY STATUS RESTARTS AGE backend-6597979bbf-njhtr 1/1 Running 0 8h frontend-5557476b4-t6pbp 1/1 Running 0 95s


8. 앱 업데이트 확인
![image](https://user-images.githubusercontent.com/11453229/135608423-bf5175d3-54fe-4e0d-bc5a-74f750f4b0a0.png)

참고
- https://docs.gitops.weave.works/docs/getting-started/
- https://github.com/weaveworks/weave-gitops
GunSik2 commented 2 years ago

오류 해결

ssh: handshake 문제

// kubectl 재설치 $ curl -LO https://dl.k8s.io/release/v1.18.0/bin/linux/amd64/kubectl $ chmod +x kubectl $ sudo mv kubectl /usr/local/bin/kubectl

// 버전 확인 $ kubectl version Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:58:59Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.20", GitCommit:"1f3e19b7beb1cc0110255668c4238ed63dadb7ad", GitTreeState:"clean", BuildDate:"2021-06-16T12:51:17Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}

GunSik2 commented 2 years ago

GitOps 개발자 환경

참고