ネットワーク経済の法則

内藤さんのおすすめ本ということで読み始めた。

「ネットワーク経済」の法則―アトム型産業からビット型産業へ…変革期を生き抜く72の指針

「ネットワーク経済」の法則―アトム型産業からビット型産業へ…変革期を生き抜く72の指針

  • 作者: カールシャピロ,ハル・R.バリアン,Carl Shapiro,Hal R. Varian,千本倖生,宮本喜一
  • 出版社/メーカー: IDGコミュニケーションズ
  • 発売日: 1999/06
  • メディア: 単行本
  • 購入: 2人 クリック: 33回
  • この商品を含むブログ (26件) を見る

第2章あたりまで進んで、そこから進まず、いったん返却。 百科事典について述べているところで、Microsoftが出した百科事典がブリタニカのそれを凌駕して置き換わったみたいな話が書いてあって、いまはWikipediaの時代になっているので、時代の流れを感じた。

もう20年近く前に書かれた本なので、古く感じるのは当然だが、法則としては現在でも有効なものがある。 また気が向いたら読むのを再開したい。

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は公式にある。

github.com

公式によると

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でログインできる。

f:id:road288:20180315132652p:plain

この後は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。

github.com

ポイントとしては、

  • 基本は kubectl apply -f [manifestのyaml] で追加されていくが、namespace -> config -> deployment -> serviceの順に適用していく。
  • minikube serviceでサービスをブラウザで開けるのはとても便利。
ᐅ minikube service --namespace=monitoring prometheus                         
Opening kubernetes service monitoring/prometheus in default browser...

f:id:road288:20180312122910p:plain

f:id:road288:20180312122928p:plain

minikubeが思ったより簡単に使えた。 新しいミドルウェアを試す環境としていいと思う。

Go言語の環境(ghq, peco)

会社のPCはgoenv入れたけど、自宅のPCはとりあえずbrew install goのみ。 あとGOPATH設定したのと、

embryo.hatenadiary.com

ここに沿ってghqとpeco入れて .zshrc

alias g='cd $(ghq root)/$(ghq list | peco)'

にしておいた。いろいろなライブラリのソース読むときに最高。 こういうのってGo独特のエコシステムというわけではないのに、Scalaを主にやっていたときには視野に入ってこなかった。 いろいろな言語をやるといいことがある。

追記: ここにもメリットがいい感じにまとまってた。

techblog.reraku.co.jp

GCSのアップロード/ダウンロードを早くする

cloudplatform.googleblog.com

  • gsutil -m でParallelに実行
  • parallel_composite_upload_threshold オプションで1ファイルあたりの分割粒度を調整
  • ファイルPATHがsequentialな名前よりは、random hashにする(アップロード完了後に名前だけ変更すればOK)
  • sliceとthreadsのオプション変更でダウンロードも早くなる

Dashlaneを使い始めた

これまでEvernoteを使ってパスワード管理していたのだけど、Evernote for Macは検索がまともに動作せず、あまりに使い勝手が悪くなってしまったのでプレミアムも解約することにして、評判のいいDashlaneを使い始めた。

これ系のパスワード管理ソフトの存在は知っていたのだけど、これまで使っていなかった。

なぜこれまで使っていなかったのかと後悔するくらいの便利さ。

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

jQuery remove table column (by column number) — SitePoint

【jQuery】要素を指定するセレクタの使い方 まとめ | Web制作会社スタイル