2018年12月30日 星期日

k8s mongo stateful

type :LoadBalancer 可連外,但無法使用 cvallance/mongo-k8s-sidecar
# kubectl exec -ti mongo-0 mongo
# rs.initiate()
# rs.conf()
# mongo mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo:27017/test
#
---
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
type: LoadBalancer
selector:
role: mongo
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
role: mongo
environment: test
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo:3.4
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "fast"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 2Gi
cvallance/mongo-k8s-sidecar
# 和google qwlke範例差在 command 和 image/ mongo 3.4版
# kubectl exec -ti mongo-0 mongo
# rs.initiate()
# rs.conf()
# mongo mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo:27017/test
#
---
apiVersion: v1
kind: Service
metadata:
name: mongo
labels:
name: mongo
spec:
ports:
- port: 27017
targetPort: 27017
clusterIP: None
selector:
role: mongo
---
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: mongo
spec:
serviceName: "mongo"
replicas: 3
template:
metadata:
labels:
role: mongo
environment: test
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mongo
image: mongo:3.4
command:
- mongod
- "--replSet"
- rs0
- "--bind_ip"
- 0.0.0.0
- "--smallfiles"
- "--noprealloc"
ports:
- containerPort: 27017
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db
- name: mongo-sidecar
image: cvallance/mongo-k8s-sidecar
env:
- name: MONGO_SIDECAR_POD_LABELS
value: "role=mongo,environment=test"
volumeClaimTemplates:
- metadata:
name: mongo-persistent-storage
annotations:
volume.beta.kubernetes.io/storage-class: "fast"
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 2Gi

2018年12月20日 星期四

解 下載檔預設是gz


const request = require('request');
const zlib = require('zlib');
const concat = require('concat-stream');

const check_place_list = () => {
return new Promise(async (resolve, reject) => {
request("https://tcgbusfs.blob.core.windows.net/blobtcmsv/TCMSV_allavailable.gz")
.pipe(zlib.createGunzip())
.pipe(concat((stringBuffer: any) => {
// console.log(stringBuffer.toString());

}));
})
}

2018年12月17日 星期一

k8s 小工具

kubectl run -i --tty alpine --image=alpine --restart=Never -- sh
kubectl exec -ti alpine /bin/sh
apk add --no-cache curl

外部curl
kubectl run example -i -t --rm --restart=Never --image centos:7 -- curl -s http://ipinfo.io/ip


開mongo image
kubectl run -it --rm --restart=Never mongo-cli --image=mongo --command -- /bin/bash
root@mongo-cli:/# mongo "mongodb://mongo-0.mongo.db,mongo-1.mongo.db,mongo-2.mongo.db:27017/test"