---
# System prepended metadata

title: Untitled

---

- 裝工具

    `brew install kubectx`

    `kubens aiqua`

`kubectl config use-context ficus.k8s.local`

### K8s commands

- 列出所有 pods

    `kubectl get pods | grep {part of pod name}`

- 看 log 訊息

    `kubectl logs -f {pod}` 

- 進到 container 裡面

- 如何 attach pod by VSCode
    - [`https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools`](https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools) 裝這個套件
    - 左邊會多個 k8s 的 tab → 選 cluster → workload → pod → 找到 pod → attach VSCode

- 重啟 pod 裡面的 UIBE
    - `kill -HUP 1`

- local 資料夾跟 pod 裡面同步
    - `devspace sync --pod {pod name}`
    - 建議在另一個資料夾做這件事

- 同步兩個資料夾內的資料

```json
#!/bin/bash
function start_moniting()
{
    echo "start morniting folder......"
    fswatch -1 .

    sleep 1
    sync_files
}

function sync_files()
{
    echo "start sync_files"
    rsync -rv --exclude=.git --exclude="common/infra/mysql/qganalyzedata.sql"  --exclude=qganalyzedata.tar.gz --exclude=rsync.sh . ../remote-aiqua-backend
    start_moniting
}

sync_files
```

### 進到 docker container 內

`docker exec -ti aiqua-ui-backend_aiqua-ui-backend-test_1 /bin/bash`

---

## How to sync with k8s pods

- **Environment prepare:**
    - Complete the AIQUA k8s setting ([Log in with Atlassian account](https://bitbucket.org/plaxieappier/k8s-kits/src/master/readme.md))
    - AWS KOPS part

         *  “pki/helm-{**team **}-ca”  -> team is **aiqua**

    * CONTEXT=ficus.k8s.local make k8s-kops-context

* `kubectl config use-context ficus.k8s.local` default is ficus.l8s.local

`2. Deploy ondemand pods`

`a. Create new branch`

`b. Copy the branch name`

`c. Got to https://jenkins-aiqua-ficus.appier.us/job/aiqua-ui-backend/job/deploy-ondemand/  -> onDemand deploy`

`d. Click “Build with parameters”`

`e. Put the branch name to deploy`

`3. Install **devspace** ([GitHub - devspace-cloud/devspace: DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.](https://github.com/devspace-cloud/devspace))`

`````

`curl -s -L "https://github.com/devspace-cloud/devspace/releases/latest" | sed -nE 's!.*"([^"]*devspace-darwin-amd64)".*!https://github.com\1!p' | xargs -n 1 curl -L -o devspace && chmod +x devspace;`

`sudo mv devspace /usr/local/bin;`

`````

`2. mkdir sync folder`

``mkdir syncFolder``

`3. run `devspace sync``

`4. Choose your ondemand k8s pod`

`5. Start sync`

- `*Sync folder to remote folder**`

``rsync -rauv --delete --progress --exclude=.git --exclude=qganalyzedata.sql --exclude=qganalyzedata.tar.gz . ../remoteBackend``

`Sync folder with “sync folder”`

`1. install fswatch`

``brew install fswatch``

`````

`fswatch $1 | while read -d "" event; do`

    `'rsync -rauv --delete --progress --exclude=.git --exclude=qganalyzedata.sql --exclude=qganalyzedata.tar.gz . ../remoteBackend'`

`done`

`````