1. 程式人生 > >阿里雲k8s服務簡單手動部署

阿里雲k8s服務簡單手動部署

通過阿里雲映象庫簡單部署應用

1、建立自己的應用映象(假設建立了 example:latest 映象)

2、docker 登入阿里雲映象庫:

   docker login --username=<youName> registry.cn-hangzhou.aliyuncs.com[映象地址]

3、輸入密碼:

4、在本地執行

    docker tag example:latest registry.cn-hangzhou.aliyuncs.com/piglet-test/example:latest
    docker push registry.cn-hangzhou.aliyuncs.com/piglet-test/example:latest

5、本地切換 namespace 並建立應用

    kubens <namspace_name>                 // 使用 kubens 的前提是得安裝它,Github上有原始碼  [ 傳送門:https://github.com/ahmetb/kubectx ]
    kubectl run <deployment_name> --image=registry.cn-hangzhou.aliyuncs.com/<images_namespace>/example:latest --port=<服務對外的介面>

使用映象使用下面其中一條去做,6 用於沒有建立應用,7 用於更新已有應用的映象

6、給deployment新增拉取映象的許可權:在yaml檔案中新增

    kubectl edit deployment <deployment_name>  // 先執行此條命令,再在彈出的編輯框中新增如下內容
    
    imagePullSecrets:
    - name: aliyun-secret
    
    kubectl expose deployment <deployment_name> --port=<應用對外暴露的埠>     // 暴露服務

7、更新映象命令

    kubectl set image deploy/<deployment_name> <deployment_name>=<image_name>:<tag>