我會把一些dockerfile和yaml的技巧性東西不按期蒐集到這裏html
三部曲:node
存儲mysql
網絡nginx
監控git
參考: https://jimmysong.io/kubernetes-handbook/appendix/tricks.htmlgithub
tomcat 啓動sql
EXPOSE 8080 CMD ["catalina.sh", "run"]
nginx日誌和啓動docker
# forward request and error logs to docker log collector RUN ln -sf /dev/stdout /var/log/nginx/access.log \ && ln -sf /dev/stderr /var/log/nginx/error.log EXPOSE 80 STOPSIGNAL SIGTERM CMD ["nginx", "-g", "daemon off;"]
apiVersion: v1 kind: Pod metadata: name: counter spec: containers: - name: count image: busybox args: [/bin/sh, -c, 'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done']
至關於centos
docker run -d --name=b1 busybox i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done
docker run -d \ --log-driver=fluentd \ --log-opt fluentd-address=localhost:24224 \ --log-opt tag="log-test-container-A" \ busybox sh -c 'while true; do echo "This is a log message from container A"; sleep 10; done;'
參考: https://kubernetes.io/docs/concepts/cluster-administration/logging/api
apiVersion: v1 kind: Pod metadata: name: counter spec: containers: - name: count image: busybox args: - /bin/sh - -c - > i=0; while true; do echo "$i: $(date)" >> /var/log/1.log; echo "$(date) INFO $i" >> /var/log/2.log; i=$((i+1)); sleep 1; done volumeMounts: - name: varlog mountPath: /var/log - name: count-log-1 image: busybox args: [/bin/sh, -c, 'tail -n+1 -f /var/log/1.log'] volumeMounts: - name: varlog mountPath: /var/log - name: count-log-2 image: busybox args: [/bin/sh, -c, 'tail -n+1 -f /var/log/2.log'] volumeMounts: - name: varlog mountPath: /var/log volumes: - name: varlog emptyDir: {}
參考: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#dns-policy
apiVersion: v1 kind: Pod metadata: name: busybox namespace: default spec: containers: - image: busybox command: - sleep - "3600" imagePullPolicy: IfNotPresent name: busybox restartPolicy: Always
## 拷貝文件不須要寫目標 FROM centos COPY 2.txt /usr/local/ ## 拷貝目錄則須要這樣寫,目標,否則拷貝不進去 FROM centos COPY mysql /usr/local/mysql
## override default time zone (Etc/UTC) if TZ variable is set if [ ! -z "$TZ" ]; then ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone fi
由於api對內地址是443
集羣api若是有3臺,則須要負載訪問,咋辦呢? 自定義svc,endpoint,實現對外負載(若是隻有一個apiserver,則直連便可)
kind: Endpoints apiVersion: v1 metadata: name: kube-apiserver-http namespace: kube-public subsets: - addresses: - ip: 192.168.x.132 - ip: 192.168.x.133 - ip: 192.168.x.134 ports: - name: http port: 8080 protocol: TCP kind: Service apiVersion: v1 metadata: labels: app-name: kube-apiserver-http name: kube-apiserver-http namespace: kube-public spec: ports: - name: http port: 80 targetPort: 8080 protocol: TCP sessionAffinity: ClientIP
參考: https://github.com/coreos/flannel/blob/master/Documentation/kube-flannel.yml
https://feisky.gitbooks.io/kubernetes/network/flannel/#cni集成
http://cizixs.com/2017/05/23/container-network-cni
command: [ "/opt/bin/flanneld", "--ip-masq", "--kube-subnet-mgr" ] securityContext: privileged: true
env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace
env: - name: MY_POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: MY_POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace - name: MY_POD_IP valueFrom: fieldRef: fieldPath: status.podIP