[DevOps] 學習 Kubernetes 筆記之一: 透過單機版的 Kubernetes (miniKube) 來玩 K8S

miniKube 單機版的 Kubernetes miniKube 是 Google 發布可以在單機上面跑 Kubernetes 的工具,安裝跟使用都相當簡單.由於會在本地跑一個 VM ,所以也不用擔心會被 Google Cloud 不小心付費的問題. 安裝 curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.6.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ 啟動 minikube start 連接進該 VM minikube ssh 打開並且顯示 minikube 的 dashboard minikube dashboard 接下來,安裝 Kubernetes 安裝 Google Cloud SDK curl https://sdk.cloud.google.com | bash 安裝好之後,會有 gcloud, gsutil 但是還需要安裝 kubectl 透過 Google Cloud SDK 安裝 Kubernetes gcloud components install kubectl 簡單 Tutorial # Startup miniKube minikube start # Create a deployment kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.4 --port=8080 # Expose it kubectl expose deployment hello-minikube --type=NodePort # Check pod kubectl get pod # Scale kubectl scale deployment hello-minikube --replicas=4 # Direct link to hello-minikube curl $(minikube service hello-minikube --url) How to Rolling Update on Kubernetes kubectl edit deployment hello-minikube Update your service version and apply it (save it back). You can also update this file via minikube dashboard Edit “deployment” Update “spec”->”spec”-> “image” version. Kubernetes 與...
繼續閱讀

[TIL] Learning note about Docker Swarm Mode

Start Docker Swarm Mode Docker Swarm Mode is specific for Docker Swarm Version 2 which only enable after Docker 1.12. It is cluster management system for Docker. Install Docker-Machine: Better to prepare at least 3 docker-machine for swarm node. If you use Docker for Mac or Docker for Windows beta, you still need install `docker-machine. Install docker-machine: curl -L https://github.com/docker/machine/releases/download/v0.7.0/docker-machine-`uname -s`-`uname -m` > /usr/local/bin/docker-machine && \ chmod +x /usr/local/bin/docker-machine Run Docker Swarm Start to create 3 docker machine for cluster management. docker-machine create --driver virtualbox v1 docker-machine create --driver virtualbox v2 docker-machine create --driver virtualbox v3 Init cluster leader in v1 docker-machine ssh v1 For example if your v1 node IP address is 192.168.99.110. docker swarm init --listen-addr 192.168.99.110:2377 --advertise-addr 192.168.99.110 Init Other Worker Node v2, v3 Let v2, v3 join cluster as nodes. Login and Control v2. docker-machine ssh v2 docker swarm join --token SWMTKN-1-3h0ndq6j0agkl1inb7sd9gnrk1va4e0sggw74jsaj7xkx75c7n-31coul06qcdb7g411ww8jnurw 192.168.99.110:2377 > This node...
繼續閱讀

[TIL] Learning note about Cassandra

Keyspace keyspace == database in SQL CREATE KEYSPACE KEYSPACE_NAME WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }; then use KEYSPACE_NAME; in cqlsh before you create/alter/drop/select tables. Special Data Operation in Cassandra (Set/List/Map/Nested Type/Frozen/Tuple/JSON) Set data Table schema for set. CREATE TABLE users ( user_id text PRIMARY KEY, first_name text, last_name text, emails set<text> ); Insert data into table INSERT INTO users (user_id, first_name, last_name, emails) VALUES('frodo', 'Frodo', 'Baggins', {'[email protected]', '[email protected]'}); List data Table schema CREATE TABLE users ( user_id text PRIMARY KEY, first_name text, last_name text, top_places list<text> ); Data Insertion. INSERT INTO users (user_id, first_name, last_name, emails) VALUES('frodo', 'Frodo', 'Baggins', [ 'rivendell', 'rohan' ]); Map Data Table schema CREATE TABLE users ( user_id text PRIMARY KEY, first_name text, last_name text, todo map<timestamp, text>; ); Data Insertion. INSERT INTO users (user_id, first_name, last_name, emails) VALUES('frodo', 'Frodo', 'Baggins', { '2012-9-24' : 'enter mordor', '2014-10-2 12:00' : 'throw ring...
繼續閱讀

[TIL] 如何快速在 Google Cloud Platform 上面架設一個 Docker 環境

Using docker-machine is another way to host your google compute instance with docker. docker-machine create \ --driver google \ --google-project $PROJECT \ --google-zone asia-east1-c \ --google-machine-type f1-micro $YOUR_INSTANCE If you want to login this machine on google cloud compute instance, just use docker-machine ssh $YOUR_INSTANCE Refer to docker machine driver gce Note: The progress of docker-machine might be slow because it need connect to Google Compute Engine. Do not use multiple docker-machine creation, because docker need to write related information on docker.sock. You might occur error on Wrapper Docker Machine process exiting due to closed plugin server (unexpected EOF). Using docker-machine to create local vbox vm will install docker 1.12 rc1, but on GCP will using 1.11. So, we could use docker swarm mode :(
繼續閱讀

[TIL] Google Cloud Storage Quickstart

Google Cloud Storage: 扁平的檔案結構,其主要架構為: Bucket (ex: gs://example) 就像是 git repo 一樣. Object 就像是檔案一樣. 存取方式 這裡先介紹透過 Google Cloud SDK 來安裝,透過以下方式可以安裝: curl https://sdk.cloud.google.com | bash 建立 Bucket gsutil mb gs://YOUR_BUCKET_NAME 複製檔案過去 gsutil cp SOURCE DESTNATION 根據這樣指令架構. 檔案放上 Google Cloud Storage: gsutil cp ./111.txt gs://YOUR_BUCKET_NAME 拉回本地端: gsutil cp gs://YOUR_BUCKET_NAME/111.txt ./ 參考: Google Doc: gcs docs GoogleCloudPlatform/storage-getting-started-go: This is a simple example of calling the Google Cloud Storage API in Go.
繼續閱讀

[Golang][FB] 教學如何快速透過 Golang 與 Heroku 架設一個臉書機器人

1. Just Deploy the same on Heroku Remember your heroku ID and app address. ex: https://APP_ADDRESS.herokuapp.com/ 2. Create a Facebook Page Make sure you already have Facebook account, if you need use FB Bot. 3. Go to Facebook Developer to create App Create App, need select as follow: New App type [Web App], create app Add new product [Messenger] 4. Configuration Messenger Bot Get token from Faccebook page. Select a “Page” you own. Go to “Meseenger” product. It will generate token copy it and store it. 5. Paste Token to Heroku Go to heroku dashboard, go to “Setting” -> “Config Variables”. Add “Config Vars” Name -> “TOKEN” Value use token facebook app. 6. Back Facebook App configuration Go to “Messenger” product Go to “Setup Webhooks” Fill https://APP_ADDRESS.herokuapp.com/webhook in callback URL. Fill your token in “token”. Checked the checkbox “message_deliveres”, “messages”. If your configuration is correct, it will show “completed”. Also...
繼續閱讀