星期日, 7月 22, 2018

Kubernetes in Azure with openSUSE Leap 15 建立小記

Kubernetes in Azure with openSUSE Leap 15 建立小記

OS:  openSUSE Leap 15
Azure-cli:  2.0.42

最近要準備新的讀書會 kubernetes up and running
所以要來準備實做環境, 目前選定 Azure 的 AKS 服務

作法有兩種

Cloud Shell 方式應該是最方便的
但是 azure cli 應該也要會使用

安裝 azure-cli

安裝 curl
# zypper  install  -y  curl

匯入 rpm key

新增 Azure CLI 的 repo
# zypper  addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli  

Adding repository 'Azure CLI' ....................................................................................................[done]
Repository 'Azure CLI' successfully added

URI         : https://packages.microsoft.com/yumrepos/azure-cli
Enabled     : Yes                                       
GPG Check   : Yes                                       
Autorefresh : No                                               
Priority    : 99 (default priority)                            

Repository priorities are without effect. All enabled repositories share the same priority.

安裝 azure-cli 套件
# zypper  install --from azure-cli  -y  azure-cli

Building repository 'Azure CLI' cache ............................................................................................[done]
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
 azure-cli

1 new package to install.
Overall download size: 20.7 MiB. Already cached: 0 B. After the operation, additional 135.5 MiB will be used.
Continue? [y/n/...? shows all options] (y): y
Retrieving package azure-cli-2.0.42-1.el7.x86_64                                                   (1/1), 20.7 MiB (135.5 MiB unpacked)
Retrieving: azure-cli-2.0.42-1.el7.x86_64.rpm ........................................................................[done (1.2 MiB/s)]
Checking for file conflicts: .....................................................................................................[done]
(1/1) Installing: azure-cli-2.0.42-1.el7.x86_64 ..................................................................................[done]

檢查 az 版本
# az   -v
azure-cli (2.0.42)

使用互動的方式登入 azure ( 現在已經不需要輸入機器碼, 直接驗證帳號就可以  )
> az  login

Note, we have launched a browser for you to login. For old experience with device code, use "az login --use-device-code"
已在目前的瀏覽器工作階段開啟新視窗。
You have logged in. Now let us find all subscriptions you have access to...

接下來參考 AKS 的快速入門來建立 Kubernets


建立資源群組, 這邊使用日東, 因為一開始用 美東, 不知道為何都失敗...
> az  group  create  --name  sakanaK8s  --location  japaneast

建立 AKS 叢集
> az aks create --resource-group sakanaK8s --name myAKScluster --node-count 1 --generate-ssh-keys

安裝 kubectl
> az  aks  install-cli
Downloading client to /usr/local/bin/kubectl from https://storage.googleapis.com/kubernetes-release/release/v1.11.1/bin/linux/amd64/kubectl
Connection error while attempting to download client ([Errno 13] Permission denied: '/usr/local/bin/kubectl')
  • 這邊失敗是因為我使用一般使用者, 對 /usr/local/bin 目錄沒有寫入權限

暫時性解法, 開啟 other 寫入權限, 然後等等再改回來
# chmod  o+w   /usr/local/bin/

> az  aks  install-cli
Downloading client to /usr/local/bin/kubectl from https://storage.googleapis.com/kubernetes-release/release/v1.11.1/bin/linux/amd64/kubectl
Please ensure that /usr/local/bin is in your search PATH, so the `kubectl` command can be found.

取得驗證資料
> az  aks  get-credentials  --resource-group  sakanaK8s --name   myAKScluster
Merged "myAKScluster" as current context in /home/sakana/.kube/config
觀察一下 config
> cat   ~/.kube/config

暫時性解法, 改回來/usr/local/bin 權限
# chmod  o-w   /usr/local/bin/

使用 kubectl 指令測試

> kubectl  get  nodes

NAME                       STATUS ROLES AGE   VERSION
aks-nodepool1-26466856-0   Ready agent 19m   v1.9.9

進行應用程式測試
建立 azure-vote.yaml


使用 kubectl apply 命令來執行應用程式

> kubectl  apply  -f  azure-vote.yaml

deployment.apps/azure-vote-back created
service/azure-vote-back created
deployment.apps/azure-vote-front created
service/azure-vote-front created

可以使用 kubectl  get service 來觀察相關資訊
> kubectl  get  service

可以觀察 azure-vote-front 的外部IP 來連線看應用程式測試的結果


刪除剛剛的應用程式

> kubectl  delete  -f  azure-vote.yaml

deployment.apps "azure-vote-back" deleted
service "azure-vote-back" deleted
deployment.apps "azure-vote-front" deleted
service "azure-vote-front" deleted


刪除剛剛建立的叢集

> az  aks  delete  --resource-group  sakanaK8s  --name  myAKScluster

Are you sure you want to perform this operation? (y/n): y


又算往 kubernetes 前進一步了

~ enjoy it

Reference



沒有留言: