helmを使ってminikube上にcoucourseを起動する
新しいミドルウェアを触ってみたい場合、まず実際に動かしてみたいと思うことが多いけど、minikubeはそれを実現するツールとして便利そうだった。 今回はそれをさらに進めて、helmを使ってみる。
いま仕事で使っているconcourseで試してみた。
まず前回の分を消してから
ᐅ minikube delete
再度新規作成する。
ᐅ minikube start Starting local Kubernetes v1.9.0 cluster... Starting VM... Getting VM IP address... Moving files into cluster... Setting up certs... Connecting to cluster... Setting up kubeconfig... Starting cluster components... Kubectl is now configured to use the cluster. Loading cached images from config file.
helmを初期化する。これによってtillerというpodがkube-system ネームスペースの中に作成される。これがk8sクラスタ内でhelmを管理しているみたい。
ᐅ helm init $HELM_HOME has been configured at /Users/xxx/.helm. Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster. Happy Helming!
helmの個々のパッケージのことをchartというが、
Charts are packages of pre-configured Kubernetes resources.
chartはk8sのリソースをまとめてパッケージ化して、これをinstallすることで、あるパッケージをそのまま利用可能にするための1つのまとまり、みたいなイメージでよさそう。
concourseのhelm chartは公式にある。
公式によると
helm install stable/concourse
これだけで実行できそうだが、実際にMacのminikube上でやると失敗する。
ᐅ helm install --name concourse stable/concourse Error: release concourse failed: clusterroles.rbac.authorization.k8s.io "concourse-web" is forbidden: attempt to grant extra privileges: [PolicyRule{Resources:["secrets"], APIGroups:[""], Verbs:["get"]}] user=&{system:serviceaccount:kube-system:default 788772bb-27fb-11e8-96cb-0800274e6818 [system:serviceaccounts system:serviceaccounts:kube-system system:authenticated] map[]} ownerrules=[] ruleResolutionErrors=[]
RBACの関係でうまくいかないらしい。
RBACとは https://kubernetes.io/docs/admin/authorization/#rbac-mode このへんなのだろうが、ひとまずアクセス権限周りは使わずに試したいので、values.ymlを編集して起動する。
https://github.com/kubernetes/charts/blob/master/stable/concourse/values.yaml#L506
このファイルを落としてきて、rbacをenableにしているこの行をfalseにする。
これで起動する。
ᐅ helm install --name concourse -f values.yaml stable/concourse NAME: concourse LAST DEPLOYED: Thu Mar 15 12:58:16 2018 NAMESPACE: default STATUS: DEPLOYED RESOURCES: ==> v1/Service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE concourse-postgresql ClusterIP 10.106.7.53 <none> 5432/TCP 0s concourse-web ClusterIP 10.97.28.26 <none> 8080/TCP,2222/TCP 0s concourse-worker ClusterIP None <none> <none> 0s ==> v1beta1/Deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE concourse-postgresql 1 1 1 0 0s concourse-web 1 1 1 0 0s ==> v1beta1/StatefulSet NAME DESIRED CURRENT AGE concourse-worker 2 2 0s ==> v1beta1/PodDisruptionBudget NAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE concourse-worker 1 N/A 0 0s ==> v1/Pod(related) NAME READY STATUS RESTARTS AGE concourse-postgresql-664df7c4cc-4nzc8 0/1 ContainerCreating 0 0s concourse-web-7f45c95c94-zthqq 0/1 ContainerCreating 0 0s concourse-worker-0 0/1 ContainerCreating 0 0s concourse-worker-1 0/1 ContainerCreating 0 0s ==> v1/Namespace NAME STATUS AGE concourse-main Active 0s ==> v1/Secret NAME TYPE DATA AGE concourse-postgresql Opaque 1 0s concourse-concourse Opaque 7 0s ==> v1/PersistentVolumeClaim NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE concourse-postgresql Bound pvc-172f7f10-2805-11e8-96cb-0800274e6818 8Gi RWO standard 0s NOTES: * Concourse can be accessed: * Within your cluster, at the following DNS name at port 8080: concourse-web.default.svc.cluster.local * From outside the cluster, run these commands in the same shell: export POD_NAME=$(kubectl get pods --namespace default -l "app=concourse-web" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use Concourse" kubectl port-forward --namespace default $POD_NAME 8080:8080 * Login with the following credentials Username: concourse Password: concourse * If this is your first time using Concourse, follow the tutorial at https://concourse.ci/hello-world.html ******************* ******WARNING****** ******************* You are using the "naive" baggage claim driver, which is also the default value for this chart. This is the default for compatability reasons, but is very space inefficient, and should be changed to either "btrfs" (recommended) or "overlay" depending on that filesystem's support in the Linux kernel your cluster is using. Please see https://github.com/concourse/concourse/issues/1230 and https://github.com/concourse/concourse/issues/1966 for background.
podの存在を確認。
ᐅ kubectl get pods NAME READY STATUS RESTARTS AGE concourse-postgresql-664df7c4cc-4nzc8 1/1 Running 0 46s concourse-web-7f45c95c94-zthqq 0/1 ContainerCreating 0 46s concourse-worker-0 0/1 ContainerCreating 0 46s concourse-worker-1 1/1 Running 0 46s
port-forwardでつないでみる。
ᐅ export POD_NAME=$(kubectl get pods --namespace default -l "app=concourse-web" -o jsonpath="{.items[0].metadata.name}") ᐅ kubectl port-forward --namespace default $POD_NAME 8080:8080 Forwarding from 127.0.0.1:8080 -> 8080 Handling connection for 8080 Handling connection for 8080 Handling connection for 8080 Handling connection for 8080
http://localhost:8080にアクセス。 デフォルトのID/Passはvalues.yamlのにも書いてあったが、concourse/concourseでログインできる。
この後はflyコマンドを使って実際にパイプラインを作ってみる。
Prometheus+Grafanaの環境をminikubeで作る
Prometheusについて知りたいと思い、実際に環境構築して動かして見たかったので、minikubeでやってみることにした。 ぐぐってみるとちょうどいいレポジトリがあったのでそれにそって作っていく。
ただ、minikubeが古かったので、まずはminikubeの環境を新しくするところから。
ᐅ minikube status E0312 11:25:18.770789 10422 status.go:85] Error cluster status: Error: Unrecognize output from GetLocalkubeStatus: sh: systemctl: not found Running ================================================================================ An error has occurred. Would you like to opt in to sending anonymized crash information to minikube to help prevent future errors? To opt out of these messages, run the command: minikube config set WantReportErrorPrompt false ================================================================================ Please enter your response [Y/n]:
謎のエラーに遭遇してしまった。minikubeのIssueによるとminikubeのバージョンが古いからのようなので、最新版をインストールする。
ᐅ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.25.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 41.2M 100 41.2M 0 0 15.5M 0 0:00:02 0:00:02 --:--:-- 15.5M Password:
ᐅ minikube version minikube version: v0.25.0
以前のminikubeクラスターがある場合はminikube delete
で消しておかないと同じエラーが出る。
minikube start
で再度 minikubeクラスターを作成。
後はこのREADMEに進めていけばOK。
ポイントとしては、
- 基本は
kubectl apply -f [manifestのyaml]
で追加されていくが、namespace -> config -> deployment -> serviceの順に適用していく。 minikube service
でサービスをブラウザで開けるのはとても便利。
ᐅ minikube service --namespace=monitoring prometheus Opening kubernetes service monitoring/prometheus in default browser...
minikubeが思ったより簡単に使えた。 新しいミドルウェアを試す環境としていいと思う。
Go言語の環境(ghq, peco)
GCSのアップロード/ダウンロードを早くする
gsutil -m
でParallelに実行parallel_composite_upload_threshold
オプションで1ファイルあたりの分割粒度を調整- ファイルPATHがsequentialな名前よりは、random hashにする(アップロード完了後に名前だけ変更すればOK)
- sliceとthreadsのオプション変更でダウンロードも早くなる
jQueryを使って今見ているページのテーブルの特定の列を消す
管理画面なんかのHTMLを見ていると、テーブルで書かれたデータの特定の行を消して見たいことがある(そもそもUI的にイケてないってことなんだけど...)。 テーブルに限らないけど、特定のDOMを消したい場合どうするか。
最近なら document.querySelector()
使えば簡単にできるのかな?最近のJavaScript詳しくなくて分からないが、ひとまずjQueryで解決する。
まずjQueryをページに動的にロードする。
var script = document.createElement("script"); script.src = "https://code.jquery.com/jquery-latest.min.js"; document.body.appendChild(script);
あとはjQueryのセレクタ使って検索して remove()
を呼ぶ。
2個めのテーブルの7列目を消す
$("table:eq(1) tr").find("th:eq(6), td:eq(6)").remove();
2個めのテーブルの7列目から13列目までを消す
$("table:eq(1) tr").find("th:gt(6):lt(13), td:gt(6):lt(13)").remove();
参考
Load javascript via Firebug console - Stack Overflow
ZonedDateTimeから日付の文字列を取り出す
よく使うのでメモ。
@ val d = ZonedDateTime.now(ZoneId.of("UTC")) d: ZonedDateTime = 2018-02-09T06:36:14.410Z[UTC]
"UTC"の部分には"Asia/Tokyo"などタイムゾーンの文字列を入れられる。
minusDays
plusHours
などで演算ができる。
@ d.minusDays(1) res5: ZonedDateTime = 2018-02-08T06:36:14.410Z[UTC]
フォーマッターを定義する。
@ val f = DateTimeFormatter.ofPattern("yyyy-MM-dd") f: DateTimeFormatter = Value(YearOfEra,4,19,EXCEEDS_PAD)'-'Value(MonthOfYear,2)'-'Value(DayOfMonth,2)
yyyy/MM/dd HH:mm:ss
が年月日時分秒に対応する。
あとはZonedDateTimeのインスタンスにフォーマッターを渡せばOK
@ d.format(f) res8: String = "2018-02-09"
参考