安装Helm到Mac电脑
首先
-
- Mac で Helmを使えるようにします
-
- 環境
server: GKE v1.10.9-gke.5
client: macOS Mojave 10.14
参考:安装Helm
操作步骤
在Mac上安装Helm的命令行工具。
$ brew install kubernetes-helm
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
esptool hexyl libnova moarvm nqp rakudo switch-lan-play
==> Updated Formulae
libidn2 ✔ django-completion fselect kitchen-sync mkcert podofo sqlmap
vim ✔ dlib geeqie less mkvtoolnix primesieve swiftlint
wget ✔ dovecot gexiv2 libetpan mozjpeg r tcc
akamai druid git-quick-stats libgxps mutt rabbitmq tor
apache-drill ed gmic libmicrohttpd nativefier rebar3 vegeta
azure-cli emacs-clang-complete-async gmt libpsl neovim recutils vips
bash eslint golang-migrate libsamplerate openconnect restic visp
boost exiv2 isync libsodium opencv scalapack whois
citus fauna-shell jabba lsdvd php-cs-fixer siril wp-cli-completion
clang-format fonttools jenkins mercurial picard-tools sox
==> Deleted Formulae
cctools cctools-headers ld64 php@5.6
==> Downloading https://homebrew.bintray.com/bottles/kubernetes-helm-2.12.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring kubernetes-helm-2.12.1.mojave.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completions have been installed to:
/usr/local/share/zsh/site-functions
==> Summary
? /usr/local/Cellar/kubernetes-helm/2.12.1: 51 files, 79.4MB
- version確認 (パスを通すため、bashは再ログイン)
$ helm version
Client: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}
Error: could not find tiller
~
在Kubernetes集群中找不到 tiller,需要安装在 Kubernetes 的集群端。
在GKE上安装Helm
- kubectlは実行できるようにしておきます。
$ kubectl cluster-info
Kubernetes master is running at https://xx.xx.xx.xx
GLBCDefaultBackend is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
Heapster is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/heapster/proxy
KubeDNS is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://xx.xx.xx.xx/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy
- kube-systemで動いているPodの一覧。 あとでみるので、先に見ておきます。
~ ❯❯❯ kubectl get pods --namespace kube-system
NAME READY STATUS RESTARTS AGE
event-exporter-v0.2.3-54f94754f4-rfnt7 2/2 Running 0 3d
fluentd-gcp-scaler-6d7bbc67c5-j62sh 1/1 Running 0 3d
fluentd-gcp-v3.1.0-4krp8 2/2 Running 0 3d
fluentd-gcp-v3.1.0-6m2tt 2/2 Running 0 3d
heapster-v1.5.3-8c5d877c7-vwt24 3/3 Running 0 3d
kube-dns-788979dc8f-7bjfh 4/4 Running 0 3d
kube-dns-788979dc8f-8v9jr 4/4 Running 0 3d
kube-dns-autoscaler-79b4b844b9-96vrw 1/1 Running 0 3d
kube-proxy-gke-kube-cluster-default-pool-50840a17-7cfv 1/1 Running 0 3d
kube-proxy-gke-kube-cluster-default-pool-50840a17-d9h1 1/1 Running 0 3d
l7-default-backend-5d5b9874d5-cjdr5 1/1 Running 0 3d
metrics-server-v0.2.1-7486f5bd67-lbgnl 2/2 Running 0 3d
~
- Tillerをインストール
$ helm init
Creating /Users/user/.helm
Creating /Users/user/.helm/repository
Creating /Users/user/.helm/repository/cache
Creating /Users/user/.helm/repository/local
Creating /Users/user/.helm/plugins
Creating /Users/user/.helm/starters
Creating /Users/user/.helm/cache/archive
Creating /Users/user/.helm/repository/repositories.yaml
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com
Adding local repo with URL: http://127.0.0.1:8879/charts
$HELM_HOME has been configured at /Users/user/.helm.
Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.
Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
Happy Helming!
~
啊,完了了。而且,kube-system中…
~ ❯❯❯ kubectl get pods --namespace kube-system
NAME READY STATUS RESTARTS AGE
(..省略..)
tiller-deploy-5b6b7d479c-67f9q 1/1 Running 0 56s
在!耕田机!
我們試試在 MongoDB 上建立一個試用的服務。
こちらを利用します
~ ❯❯❯ helm repo update ✘ 1
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
~ ❯❯❯
~ ❯❯❯
~ ❯❯❯ helm install stable/mongodb
Error: no available release name found
~
一想到这个,就出现了错误。
因为有其他人遇到了相同的情况,所以我参考了他们的经验。
只有在执行以下步骤后才能成功。
当使用 k8s helm 时,出现了错误:找不到可用的发布名称。
我对于 k8s 的用户权限方面还一点儿都不懂…接下来我会好好学习的。
$ kubectl create serviceaccount --namespace kube-system tiller
$ kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
$ kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
~ ❯❯❯ helm install stable/mongodb
NAME: flabby-puma
LAST DEPLOYED: Tue Jan 8 23:20:24 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
flabby-puma-mongodb ClusterIP 10.15.254.242 <none> 27017/TCP 1s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
flabby-puma-mongodb 1 1 1 0 1s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
flabby-puma-mongodb-657f46c8b5-6gxbc 0/1 Pending 0 1s
==> v1/Secret
NAME TYPE DATA AGE
flabby-puma-mongodb Opaque 1 1s
==> v1/PersistentVolumeClaim
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
flabby-puma-mongodb Pending standard 1s
NOTES:
** Please be patient while the chart is being deployed **
MongoDB can be accessed via port 27017 on the following DNS name from within your cluster:
flabby-puma-mongodb.default.svc.cluster.local
To get the root password run:
export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace default flabby-puma-mongodb -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)
To connect to your database run the following command:
kubectl run --namespace default flabby-puma-mongodb-client --rm --tty -i --restart='Never' --image bitnami/mongodb --command -- mongo admin --host flabby-puma-mongodb --authenticationDatabase admin -u root -p $MONGODB_ROOT_PASSWORD
To connect to your database from outside the cluster execute the following commands:
kubectl port-forward --namespace default svc/flabby-puma-mongodb 27017:27017 &
mongo --host 127.0.0.1 --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD
完成了!
- kubectl
~ ❯❯❯ kubectl get pods
NAME READY STATUS RESTARTS AGE
flabby-puma-mongodb-657f46c8b5-6gxbc 1/1 Running 0 2m
看起来现在至少是在运作中,所以这次就到这里吧。