EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/
顯示具有 kubernetes 標籤的文章。 顯示所有文章
顯示具有 kubernetes 標籤的文章。 顯示所有文章

kubernetes K3s Failed!

Failed reason: Node port range can't fixed!


K3s


##### install #####
curl -sfL https://get.k3s.io | sh -


##### login https://192.168.99.119:6443/ get username/password #####
more /etc/rancher/k3s/k3s.yaml


##### change node-port range #####
k3s server --kube-apiserver-arg --service-node-port-range=1-65535


##### install dashboard #####
k3s kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml --insecure-skip-tls-verify

k3s kubectl create secret generic kubernetes-dashboard-certs --from-file=certs -n kube-system

k3s kubectl apply -f dashboard-ClusterRoleBinding.yaml
k3s kubectl apply -f dashboard-adminuser.yaml
k3s kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

Find admin-user-token

https://192.168.99.119:30393/


##### kill all #####
k3s-killall.sh
k3s-uninstall.sh

##### start k3s service #####
service k3s status ## check k3s is stop
service k3s start

[轉]Kubernetes 调整 nodePort 端口范围

https://qhh.me/2019/08/pod 文件定义在 /etc/kubernetes/manifests/kube-apiserver.yaml15/Kubernetes-%E8%B0%83%E6%95%B4-nodePort-%E7%AB%AF%E5%8F%A3%E8%8C%83%E5%9B%B4/

在 command 下添加 --service-node-port-range=1-65535 参数,修改后会自动生效,无需其他操作:



apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    component: kube-apiserver
    tier: control-plane
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
    - --service-node-port-range=1-65535
    - --advertise-address=192.168.26.10
    - --allow-privileged=true
    - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --enable-admission-plugins=NodeRestriction
    - --enable-bootstrap-token-auth=true
    - --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
    - --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt
    - --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key
    - --etcd-servers=https://127.0.0.1:2379
    - --insecure-port=0
    - --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt
    - --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key
    - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
    - --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
    - --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
    - --requestheader-allowed-names=front-proxy-client
    - --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
    - --requestheader-extra-headers-prefix=X-Remote-Extra-
    - --requestheader-group-headers=X-Remote-Group
    - --requestheader-username-headers=X-Remote-User
    - --secure-port=6443
    - --service-account-key-file=/etc/kubernetes/pki/sa.pub
    - --service-cluster-ip-range=10.96.0.0/12
    - --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
    - --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
    image: registry.aliyuncs.com/google_containers/kube-apiserver:v1.15.2
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 192.168.26.10
        path: /healthz
        port: 6443
        scheme: HTTPS
      initialDelaySeconds: 15
      timeoutSeconds: 15
    name: kube-apiserver
    resources:
      requests:
        cpu: 250m
    volumeMounts:
    - mountPath: /etc/ssl/certs
      name: ca-certs
      readOnly: true
    - mountPath: /etc/pki
      name: etc-pki
      readOnly: true
    - mountPath: /etc/kubernetes/pki
      name: k8s-certs
      readOnly: true
  hostNetwork: true
  priorityClassName: system-cluster-critical
  volumes:
  - hostPath:
      path: /etc/ssl/certs
      type: DirectoryOrCreate
    name: ca-certs
  - hostPath:
      path: /etc/pki
      type: DirectoryOrCreate
    name: etc-pki
  - hostPath:
      path: /etc/kubernetes/pki
      type: DirectoryOrCreate
    name: k8s-certs
status: {}

k8s kubernetes Lesson 8 Error

Error: User "system:serviceaccount:kube-system:default" cannot get resource "namespaces"


https://github.com/fnproject/fn-helm/issues/21#issuecomment-545317241


kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
helm init --upgrade --service-account tiller

docker registry Other Way


On root home

openssl req -nodes -newkey rsa:4096 -keyout certs/docker-registry.key -out certs/docker-registry.csr -subj "/C=/ST=/L=/O=/OU=/CN=docker-registry"
openssl x509 -req -sha256 -days 365 -in certs/docker-registry.csr -signkey certs/docker-registry.key -out certs/docker-registry.crt


docker run -dp 5000:5000 --name registry -v "$(pwd)"/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/docker-registry.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/docker-registry.key \
registry


nano /etc/hosts 
> 192.168.99.118 docker-registry

cd /etc/docker
mkdir certs.d
cd certs.d
mkdir docker-registry:5000
cd docker-registry:5000
cp ~/certs/docker-registry.crt ca.crt

===== check registry is working
docker image pull busybox
docker image tag busybox docker-registry:5000/mybusybox
docker image push docker-registry:5000/mybusybox
docker run --rm docker-registry:5000/mybusybox echo "Hello from busybox"

//
docker rmi busybox docker-registry:5000/mybusybox
docker run --rm docker-registry:5000/mybusybox echo "Hello from busybox"

===== remove registry
docker container stop registry && docker container rm -v registry



https://jkzhao.github.io/2017/09/01/Registry%E7%A7%81%E6%9C%89%E4%BB%93%E5%BA%93%E6%90%AD%E5%BB%BA%E5%8F%8A%E8%AE%A4%E8%AF%81/

列出私有仓库中的所有镜像

curl -k -X GET https://docker-registry:5000/v2/_catalog  >> {"repositories":["mybusybox"]}

curl --cacert certs/docker-registry.crt https://docker-registry:5000/v2/_catalog

curl -k https://docker-registry:5000/v2/_catalog

k8s kubernetes Lesson 7 ingress-nginx kubernetes

https://sueboy.blogspot.com/2019/01/ingress-nginx-kubernetes-ingress-with.html

Real site is


https://kubernetes.github.io/ingress-nginx/deploy/


kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml


Verify installation

https://kubernetes.github.io/ingress-nginx/deploy/#verify-installation


kubectl get pods --all-namespaces -l app.kubernetes.io/name=ingress-nginx --watch


Detect installed version

https://kubernetes.github.io/ingress-nginx/deploy/#detect-installed-version


shell script

POD_NAMESPACE=ingress-nginx
POD_NAME=$(kubectl get pods -n $POD_NAMESPACE -l app.kubernetes.io/name=ingress-nginx -o jsonpath='{.items[0].metadata.name}')
kubectl exec -it $POD_NAME -n $POD_NAMESPACE -- /nginx-ingress-controller --version


=========

Other nginx-ingress

https://kubernetes.github.io/ingress-nginx/deploy/#using-helm

[轉]How To Create a Kubernetes Cluster Using Kubeadm on Debian 9

https://www.digitalocean.com/community/tutorials/how-to-create-a-kubernetes-cluster-using-kubeadm-on-debian-9

k8s nfs v4 kubernetes

https://hub.docker.com/r/itsthenetwork/nfs-server-alpine

https://sueboy.blogspot.com/2019/11/kubernetes-nodeport.html

ConfigMap


apiVersion: v1
kind: ConfigMap
metadata:
  name: nfs
  namespace: nfs
data:
  exports: |
    {{SHARED_DIRECTORY}} {{PERMITTED}}({{READ_ONLY}},fsid=0,{{SYNC}},no_subtree_check,no_auth_nlm,insecure,no_root_squash)
  nfsd: |
    #!/bin/bash

    # Make sure we react to these signals by running stop() when we see them - for clean shutdown
    # And then exiting
    trap "stop; exit 0;" SIGTERM SIGINT

    stop()
    {
      # We're here because we've seen SIGTERM, likely via a Docker stop command or similar
      # Let's shutdown cleanly
      echo "SIGTERM caught, terminating NFS process(es)..."
      /usr/sbin/exportfs -uav
      /usr/sbin/rpc.nfsd 0
      pid1=`pidof rpc.nfsd`
      pid2=`pidof rpc.mountd`
      # For IPv6 bug:
      pid3=`pidof rpcbind`
      kill -TERM $pid1 $pid2 $pid3 > /dev/null 2>&1
      echo "Terminated."
      exit
    }
    
    # Check if the SHARED_DIRECTORY variable is empty
    if [ -z "${SHARED_DIRECTORY}" ]; then
      echo "The SHARED_DIRECTORY environment variable is unset or null, exiting..."
      exit 1
    else
      echo "Writing SHARED_DIRECTORY to /etc/exports file"
      /bin/sed -i "s@{{SHARED_DIRECTORY}}@${SHARED_DIRECTORY}@g" /etc/exports
    fi

    # This is here to demonsrate how multiple directories can be shared. You
    # would need a block like this for each extra share.
    # Any additional shares MUST be subdirectories of the root directory specified
    # by SHARED_DIRECTORY.

    # Check if the SHARED_DIRECTORY_2 variable is empty
    if [ ! -z "${SHARED_DIRECTORY_2}" ]; then
      echo "Writing SHARED_DIRECTORY_2 to /etc/exports file"
      echo "{{SHARED_DIRECTORY_2}} {{PERMITTED}}({{READ_ONLY}},{{SYNC}},no_subtree_check,no_auth_nlm,insecure,no_root_squash)" >> /etc/exports
      /bin/sed -i "s@{{SHARED_DIRECTORY_2}}@${SHARED_DIRECTORY_2}@g" /etc/exports
    fi

    # Check if the PERMITTED variable is empty
    if [ -z "${PERMITTED}" ]; then
      echo "The PERMITTED environment variable is unset or null, defaulting to '*'."
      echo "This means any client can mount."
      /bin/sed -i "s/{{PERMITTED}}/*/g" /etc/exports
    else
      echo "The PERMITTED environment variable is set."
      echo "The permitted clients are: ${PERMITTED}."
      /bin/sed -i "s/{{PERMITTED}}/"${PERMITTED}"/g" /etc/exports
    fi

    # Check if the READ_ONLY variable is set (rather than a null string) using parameter expansion
    if [ -z ${READ_ONLY+y} ]; then
      echo "The READ_ONLY environment variable is unset or null, defaulting to 'rw'."
      echo "Clients have read/write access."
      /bin/sed -i "s/{{READ_ONLY}}/rw/g" /etc/exports
    else
      echo "The READ_ONLY environment variable is set."
      echo "Clients will have read-only access."
      /bin/sed -i "s/{{READ_ONLY}}/ro/g" /etc/exports
    fi

    # Check if the SYNC variable is set (rather than a null string) using parameter expansion
    if [ -z "${SYNC+y}" ]; then
      echo "The SYNC environment variable is unset or null, defaulting to 'async' mode".
      echo "Writes will not be immediately written to disk."
      /bin/sed -i "s/{{SYNC}}/async/g" /etc/exports
    else
      echo "The SYNC environment variable is set, using 'sync' mode".
      echo "Writes will be immediately written to disk."
      /bin/sed -i "s/{{SYNC}}/sync/g" /etc/exports
    fi

    # Partially set 'unofficial Bash Strict Mode' as described here: http://redsymbol.net/articles/unofficial-bash-strict-mode/
    # We don't set -e because the pidof command returns an exit code of 1 when the specified process is not found
    # We expect this at times and don't want the script to be terminated when it occurs
    set -uo pipefail
    IFS=$'\n\t'

    # This loop runs till until we've started up successfully
    while true; do

      # Check if NFS is running by recording it's PID (if it's not running $pid will be null):
      pid=`pidof rpc.mountd`

      # If $pid is null, do this to start or restart NFS:
      while [ -z "$pid" ]; do
        echo "Displaying /etc/exports contents:"
        cat /etc/exports
        echo ""

        # Normally only required if v3 will be used
        # But currently enabled to overcome an NFS bug around opening an IPv6 socket
        echo "Starting rpcbind..."
        /sbin/rpcbind -w
        echo "Displaying rpcbind status..."
        /sbin/rpcinfo

        # Only required if v3 will be used
        # /usr/sbin/rpc.idmapd
        # /usr/sbin/rpc.gssd -v
        # /usr/sbin/rpc.statd

        echo "Starting NFS in the background..."
        /usr/sbin/rpc.nfsd --debug 8 --no-udp --no-nfs-version 2 --no-nfs-version 3
        echo "Exporting File System..."
        if /usr/sbin/exportfs -rv; then
          /usr/sbin/exportfs
        else
          echo "Export validation failed, exiting..."
          exit 1
        fi
        echo "Starting Mountd in the background..."These
        /usr/sbin/rpc.mountd --debug all --no-udp --no-nfs-version 2 --no-nfs-version 3
    # --exports-file /etc/exports

        # Check if NFS is now running by recording it's PID (if it's not running $pid will be null):
        pid=`pidof rpc.mountd`

        # If $pid is null, startup failed; log the fact and sleep for 2s
        # We'll then automatically loop through and try again
        if [ -z "$pid" ]; then
          echo "Startup of NFS failed, sleeping for 2s, then retrying..."
          sleep 2
        fi

      done

      # Break this outer loop once we've started up successfully
      # Otherwise, we'll silently restart and Docker won't know
      echo "Startup successful."
      break

    done

    while true; do

      # Check if NFS is STILL running by recording it's PID (if it's not running $pid will be null):
      pid=`pidof rpc.mountd`
      # If it is not, lets kill our PID1 process (this script) by breaking out of this while loop:
      # This ensures Docker observes the failure and handles it as necessary
      if [ -z "$pid" ]; then
        echo "NFS has failed, exiting, so Docker can restart the container..."
        break
      fi

      # If it is, give the CPU a rest
      sleep 1

    done

    sleep 1
    exit 1
  bashrc: |
    # General Aliases
    alias apk='apk --progress'
    alias ll="ls -ltan"

    alias hosts='cat /etc/hosts'
    alias ..="cd .."
    alias ...="cd ../.."
    alias ....="cd ../../.."
    alias untar="tar xzvkf"
    alias mv="mv -nv"
    alias cp="cp -i"
    alias ip4="ip -4 addr"
    alias ip6="ip -6 addr"

    COL_YEL="\[\e[1;33m\]"
    COL_GRA="\[\e[0;37m\]"
    COL_WHI="\[\e[1;37m\]"
    COL_GRE="\[\e[1;32m\]"
    COL_RED="\[\e[1;31m\]"

    # Bash Prompt
    if test "$UID" -eq 0 ; then
        _COL_USER=$COL_RED
        _p=" #"
    else
        _COL_USER=$COL_GRE
        _p=">"
    fi
    COLORIZED_PROMPT="${_COL_USER}\u${COL_WHI}@${COL_YEL}\h${COL_WHI}:\w${_p} \[\e[m\]"
    case $TERM in
        *term | rxvt | screen )
            PS1="${COLORIZED_PROMPT}\[\e]0;\u@\h:\w\007\]" ;;
        linux )
            PS1="${COLORIZED_PROMPT}" ;;
        * ) 
            PS1="\u@\h:\w${_p} " ;;
    esac


Deployment

Different is ln /exports/exports /etc/exports
ConfigMAP /etc have read-only problem


apiVersion: apps/v1
kind: Deployment
metadata:
  name: nfs-service
  namespace: nfs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nfs-service
  template:
    metadata:
      labels:
        app: nfs-service
    spec:
      #restartPolicy: Always
      volumes:
        - name: exports
          configMap:
            name: nfs
            items:
              - key: exports
                path: exports
                mode: 0744
        - name: nfsd
          configMap:
            name: nfs
            items:
              - key: nfsd
                path: nfsd.sh
                mode: 0744
        - name: bashrc
          configMap:
            name: nfs
            items:
              - key: bashrc
                path: .bashrc
                mode: 0744
        - name: nfsshare
          emptyDir: {}  
      containers:
        - name: nfs-server-container
          image: alpine:latest
          securityContext:
            privileged: true
          command:
            - /bin/sh
            - -c
            - |
              echo nameserver 8.8.8.8 >> /etc/resolv.conf
              apk add --no-cache --update --verbose nfs-utils bash iproute2 
              rm -rf /var/cache/apk /tmp /sbin/halt /sbin/poweroff /sbin/reboot 
              mkdir -p /var/lib/nfs/rpc_pipefs /var/lib/nfs/v4recovery 
              echo "rpc_pipefs    /var/lib/nfs/rpc_pipefs rpc_pipefs      defaults        0       0" >> /etc/fstab 
              echo "nfsd  /proc/fs/nfsd   nfsd    defaults        0       0" >> /etc/fstab 
              rm /etc/exports 
              cp /exports/exports /etc/exports 
              cp /nfsd/nfsd.sh /usr/bin/nfsd.sh
              cp /bashrc/.bashrc /root/.bashrc
              chmod +x /usr/bin/nfsd.sh
              /usr/bin/nfsd.sh
          env:
            - name: SHARED_DIRECTORY
              value: "/nfsshare"
          volumeMounts:
            - name: exports
              mountPath: /exports
              #readOnly: true
            - name: nfsd
              mountPath: /nfsd
            - name: bashrc
              mountPath: /bashrc 
            - name: nfsshare
              mountPath: /nfsshare 

k8s ConfigMap mountPath need becarful. like this example exports and nfsd are /etc & /usr/bin. This two directory already have file inside. When you director mountPath: /etc or mountPath: /usr/bin . k8s replace this two path to other direcotry. ls -al /etc or /usr/bin that only get exports file and nfsd.sh file. So better way is mountPath usually different directory. In shell: Use Copy that copy exprots file and nfsd.sh file to docker image correct directory.


Service


kind: Service
apiVersion: v1
metadata:
  name: nfs-service
  namespace: nfs
spec:
  selector:
    app: nfs-service
  type: NodePort
  ports:
    # Open the ports required by the NFS server
    # Port 2049 for TCP
    - name: tcp-2049
      port: 2049
      targetPort: 2049
      protocol: TCP
      nodePort: 32049

    # Port 111 for UDP
    - name: udp-111
      port: 111
      protocol: UDP



======nfs v4 client mount
debain
https://blog.gtwang.org/linux/nfsv4/

Centos
https://computingforgeeks.com/configure-nfsv3-and-nfsv4-on-centos-7/


$ sudo yum -y install nfs-utils
$ sudo systemctl start rpcbind 
$ sudo systemctl enable rpcbind

mount -v -o port=32049 -o vers=4 -t nfs 192.168.99.118:/ /tmp/tnfs/
nano /tmp/tnfs/tt  # save some text. Then check nfs pod /nfsshare have tt and tt context



kubernetes Deployment Failed to fetch Temporary failure resolving

IF you apt-get update in k8s Deployment yaml that containers command run it. Maybe get

Deployment Failed to fetch Temporary failure resolving


So just put this line before script


- /bin/bash
- -c
- |
  echo nameserver 8.8.8.8 >> /etc/resolv.conf
  apt-get update


Usually you get this problem because try to transfer Dockerfile / docker-compose directory to ConfigMap and Deployment YAML. Dockerfile have apt-get update that get problem.

[轉]你到底知不知道什麼是 Kubernetes?

https://www.hwchiu.com/kubernetes-concept.html


然而通常 A/B/C/D 都不是底下的工程人員,所以最後都會變成用嘴巴生架構,用嘴巴解決問題,底下實際的工程人員則是各種崩潰

k8s kubernetes Lesson 6 yaml docker-registry cron part 2 No minikube

normal k8s

https://sueboy.blogspot.com/2019/11/kubernetes-nodeport.html

namespace docker-registry

{
  "kind": "Namespace",
  "apiVersion": "v1",
  "metadata": {
    "name": "docker-registry",
    "labels": {
      "name": "test-dev"
    }
  }
}



secret.yml ID/PWD:username/password tls:cn=docker-registry

apiVersion: v1
kind: Secret
metadata:
  name: registry-tls
  namespace: docker-registry
type: Opaque
data:
  tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVzRENDQXBnQ0NRRHpteitOQUZCMGRUQU5CZ2txaGtpRzl3MEJBUXNGQURBYU1SZ3dGZ1lEVlFRRERBOWsKYjJOclpYSXRjbVZuYVhOMGNua3dIaGNOTVRrd01qSTJNVEF3TlRBMldoY05NakF3TWpJMk1UQXdOVEEyV2pBYQpNUmd3RmdZRFZRUUREQTlrYjJOclpYSXRjbVZuYVhOMGNua3dnZ0lpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElDCkR3QXdnZ0lLQW9JQ0F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yV0pKc0tqcWx3RC5BQmpLcUswc2R0SU9lZ29kb3VrQzFpR0owc05ENjhD


configmap.yml

apiVersion: v1
kind: ConfigMap
metadata:
  name: docker-registry
  namespace: docker-registry
data:
  registry-config.yml: |
    version: 0.1
    log:
      fields:
        service: registry
    storage:
      delete:
        enabled: true
      cache:
        blobdescriptor: inmemory
      filesystem:
        rootdirectory: /var/lib/registry
    http:
      addr: :5000
      host: https://docker-registry:30500
      secret: asecretforlocaldevelopment
      headers:
        X-Content-Type-Options: [nosniff]
        Access-Control-Allow-Origin: ['*']
        Access-Control-Allow-Methods: ['HEAD', 'GET', 'OPTIONS', 'DELETE']
        Access-Control-Allow-Headers: ['Authorization']
        Access-Control-Max-Age: [1728000]
        Access-Control-Allow-Credentials: [true]
        Access-Control-Expose-Headers: ['Docker-Content-Digest']
      tls:
        certificate: /cert/x509/public
        key: /cert/x509/private
    auth:
      htpasswd:
        realm: basic-realm
        path: /auth/htpasswd
    health:
      storagedriver:
        enabled: true
        interval: 10s
        threshold: 3


deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: registry
  namespace: docker-registry
spec:
  replicas: 2
  selector:
    matchLabels:
      app: registry
  template:
    metadata:
      labels:
        app: registry
    spec:
      #restartPolicy: Always
      volumes:
        - name: config
          configMap:
            name: docker-registry
            items:
              - key: registry-config.yml
                path: config.yml
        - name: cert
          secret:
            secretName: registry-tls
            items:
              - key: tls.crt
                path: public
              - key: tls.key
                path: private  
        - name: htpasswd
          secret:
            secretName: registry-tls
            items:
              - key: HTPASSWD
                path: htpasswd
        - name: registry-data
          emptyDir: {}  
      containers:
        - name: registry
          image: registry:2.7.1
          ports:
            - name: http
              containerPort: 5000
              protocol: TCP
          volumeMounts:
            - name: config
              mountPath: /etc/docker/registry
              readOnly: true
            - name: cert
              mountPath: /cert/x509
              readOnly: true
            - name: htpasswd
              mountPath: /auth
              readOnly: true
            - name: registry-data
              mountPath: /var/lib/registry


service.yml

apiVersion: v1
kind: Service
metadata:
  name: docker-registry
  namespace: docker-registry
spec:
  type: NodePort
  ports:
  - name: registryhttp
    port: 5000
    targetPort: 5000
    nodePort: 30500
  selector:
    app: registry


===== docker-compose =====

docker-compose.yml

version: '3.3'

services:
  gethpeers:
    build:
      context: gethpeers/
    image: docker-registry:30500/username/gethpeers
    volumes:
      - cronlog:/app/cronapplog:rw
      - /etc/localtime:/etc/localtime:ro
    networks:
      - fastdev

  fakelog:
    build:
      context: fakelog/
    image: docker-registry:30500/username/fakelog
    volumes:
      - cronlog:/app/cronapplog:rw
      - filebeat:/usr/share/filebeat/data:rw
    networks:
      - fastdev

volumes:  
  cronlog: 
  filebeat:
  
networks:
  fastdev:
    driver: bridge


fakelog/Dockerfile

FROM docker.elastic.co/beats/filebeat:6.5.4
COPY filebeat.yml /usr/share/filebeat/filebeat.yml
USER root
RUN chown root:filebeat /usr/share/filebeat/filebeat.yml
USER filebeat


fakelog/filebeat.yml

filebeat.prospectors:

- type: log
  paths:
    - /app/cronapplog/*.log
  exclude_files: ['.gz$']
  fields_under_root: true
  symlinks: true

output.logstash:
  hosts: ["logstash:5044"]


cron/crontab

* * * * * /app/run-cronjob.sh /app/start.sh > /proc/1/fd/1 2>/proc/1/fd/2
#* * * * * echo hello > /proc/1/fd/1 2>/proc/1/fd/2


cron/Dockerfile

FROM debian:stretch-slim
RUN apt-get -y update && apt-get install -y cron curl jq nano iputils-ping net-tools && \
    rm -r /var/lib/apt/lists/*
ADD . /app
ADD crontab /var/spool/cron/crontabs/root
RUN chmod 0600 /var/spool/cron/crontabs/root
RUN chmod +x /app/run-cronjob.sh
RUN chmod +x /app/start.sh
CMD cron -f


cron/run-cronjob.sh

#!/bin/bash

if [ -z "$1" ] ; then
  echo "need name of cron job as first argument" > /proc/1/fd/1 2>/proc/1/fd/2
  exit 1
fi
 
if [ ! -x "$1" ] ; then
  echo "cron job file $1 not executable, exiting" > /proc/1/fd/1 2>/proc/1/fd/2
  exit 1
fi
 
if "$1"
then
  echo "cron job $1 Run!" > /proc/1/fd/1 2>/proc/1/fd/2
  exit 0
else
  echo "cron job $1 failed!" > /proc/1/fd/1 2>/proc/1/fd/2
  exit 1
fi


cron/start.sh

#!/bin/bash

# geth get admin.peers
IP_PORT=xxx.xxx.xxx.xxx.xxx
ETH_METHOD=admin_peers
PEERS=$(curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"'$ETH_METHOD'","params":[],"id":1}' $IP_PORT |  jq -c '.result[].network + {"run":"curl json"}')

printf "\n===== Now Geth Peers =====\n"
#printf "Peers: %s\n" $PEERS
echo $PEERS | jq .
#echo $PEERS >> /app/cronapplog/gethpeers.log
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"'$ETH_METHOD'","params":[],"id":1}' $IP_PORT |  jq -c '.result[].network + {"run":"curl json"}' >> /app/cronapplog/gethpeers.log



===== push image to docker-registry =====

nano /etc/docker/daemon.json
{
  "insecure-registries" : ["docker-registry:30500"]
}
service docker restart

docker login -u username -p password docker-registry:30500
docker-compose push

nano /etc/hosts
192.168.99.118 docker-registry

check https://docker-registry:30500/v2/_catalog  
#check result
{"repositories":["username/fakelog","username/gethpeers"]}


IF get error

ERROR: blob upload unknown

when docker-compose push

Deployment replicase 2 -> 1



apiVersion: apps/v1
kind: Deployment
metadata:
  name: registry
  namespace: docker-registry
spec:
  replicas: 1


===== docker-registry ui =====
===== docker =====
docker run -d -p 80:80 -e URL=http://192.168.99.118 -e REGISTRY_URL=https://192.168.99.118:30500 -e DELETE_IMAGES=true joxit/docker-registry-ui:static

broswer http://192.168.99.118

[轉][教學] 用Drone, Kubernetes跟Helm,以及RBAC來建置你的CI/CD流程

Part 1 https://medium.com/@cloudsanchen/ci-cd-with-drone-kubernetes-and-helm-part-1-69c147046ffa

Part 2 https://medium.com/@cloudsanchen/ci-cd-with-drone-kubernetes-and-helm-part-2-65b43d790b30

part 3 https://medium.com/@cloudsanchen/%E6%95%99%E5%AD%B8-%E7%94%A8drone-kubernetes%E8%B7%9Fhelm-%E4%BB%A5%E5%8F%8Arbac%E4%BE%86%E5%BB%BA%E7%BD%AE%E4%BD%A0%E7%9A%84ci-cd%E6%B5%81%E7%A8%8B-part-3-de7273591bb

k8s kubernetes Lesson 4 RKE

Use RKE only one YAML config

https://itnext.io/setup-a-basic-kubernetes-cluster-with-ease-using-rke-a5f3cc44f26f

[轉]"migrating" to Kubernetes from docker-compose in homelab

https://www.reddit.com/r/docker/comments/9j2vc7/migrating_to_kubernetes_from_dockercompose_in/


If / when you're able to spawn arbitrary VMs, you can look at kubeadm, CoreOS, RKE (my current choice), and so on for cluster creation.



Before you can use kompose, or use kubectl apply -f myawesome.yaml, you first and foremost need to set up a Kubernetes cluster. This might be the most challenging thing to do because Kubernetes is heavy-weight compared to docker-compose. I recommend using RKE to set it up. Also, run away if anyone mentions Kubespray.


=====

RKE ???

YAML multi-line string

https://rancher.com/docs/rke/v0.1.x/en/config-options/add-ons/user-defined-add-ons/


To define an add-on directly in the YAML file, make sure to use the YAML’s block indicator

|-

as the addons directive is a multi-line string option. It’s possible to specify multiple YAML resource definitions by separating them using the

---

directive.

k8s kubernetes Lesson 3 k8s by hand

Kubernetes wiki
https://wiki.gslin.org/wiki/Kubernetes

How to Install a Kubernetes Docker Cluster on CentOS 7
https://www.howtoforge.com/tutorial/centos-kubernetes-docker-cluster/
https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

https://sueboy.blogspot.com/2019/11/kubernetes-nodeport.html

https://rickhw.github.io/2019/03/17/Container/Install-K8s-with-Kubeadm/

=====
https://www.howtoforge.com/tutorial/centos-kubernetes-docker-cluster/

only one master/node k8s



yum update

setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

swapoff -a

vim /etc/fstab     >> mark swap

yum install -y yum-utils device-mapper-persistent-data lvm2

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce

cat << eof > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
        https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet kubeadm kubectl

sudo reboot  


systemctl start docker && systemctl enable docker
systemctl start kubelet && systemctl enable kubelet

docker info | grep -i cgroup

sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

systemctl daemon-reload
systemctl restart kubelet


## kubeadm init --apiserver-advertise-address=10.0.15.10 --pod-network-cidr=10.244.0.0/16
kubeadm init --pod-network-cidr=10.244.0.0/16

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

kubectl get nodes
kubectl get pods --all-namespaces

https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#control-plane-node-isolation

kubectl taint nodes --all node-role.kubernetes.io/master-

If use calico
https://docs.projectcalico.org/v3.5/getting-started/kubernetes/

DNS

https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/#are-dns-queries-being-received-processed


kubectl -n kube-system edit configmap coredns

# Add log
data:
  Corefile: |
    .:53 {
        log
        errors

PS: As 10.96.0.10 is a Cluster IP, It is not ping-able. You can use telnet or curl.

https://github.com/kubernetes/kubernetes/issues/78926#issuecomment-503898794
So use nslookup


#check DNS
注意: 不要使用busybox:latest,最高版本的nslookup工具有bug

apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: default
spec:
  containers:
  - name: busybox
    image: busybox:1.28.4
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
  restartPolicy: Always

kubectl exec -ti busybox -- nslookup kubernetes.default

#check DNS log
for p in $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name); do kubectl logs --namespace=kube-system $p; done

PS: If need to kubeadm reset ... see bootom

Dashboard



##### dashboard
wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

#modify clusterip -> nodeport
nano kubernetes-dashboard.yaml
# ------------------- Dashboard Service ------------------- #

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30393
  selector:
    k8s-app: kubernetes-dashboard

kubectl apply -n kube-system -f kubernetes-dashboard.yaml
kubectl -n kube-system get service kubernetes-dashboard



[root@localhost ~]# kubectl -n kube-system get service kubernetes-dashboard
NAME                   TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)         AGE
kubernetes-dashboard   NodePort   10.110.11.88           443:30393/TCP   103

use 30393 EX: https://192.168.99.118:30393 (192.168.99.118 is virtualbox give ip)



Dashboard ERROR NET::ERR_CERT_INVALID

https://github.com/kubernetes/dashboard/issues/2954
https://github.com/kubernetes/dashboard/wiki/Certificate-management

-subj "/C=/ST=/L=/O=/OU=/CN=kubernetes-dashboard"


mkdir certs  ( At user home path )
openssl req -nodes -newkey rsa:2048 -keyout certs/dashboard.key -out certs/dashboard.csr -subj "/C=/ST=/L=/O=/OU=/CN=kubernetes-dashboard"
openssl x509 -req -sha256 -days 365 -in certs/dashboard.csr -signkey certs/dashboard.key -out certs/dashboard.crt

kubectl delete -f kubernetes-dashboard.yaml
kubectl create secret generic kubernetes-dashboard-certs --from-file=certs -n kube-system
kubectl create -f kubernetes-dashboard.yaml

Try again. https://192.168.99.118:30393





Get Dashboard token

https://github.com/kubernetes/dashboard/wiki/Creating-sample-user


nano dashboard-adminuser.yaml


apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kube-system


kubectl create -f dashboard-adminuser.yaml

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

If see admin-user token, just copy token pass to web login.

IF Get Error

try to Create ClusterRoleBinding

Create dashboard-ClusterRoleBinding.yaml



apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kube-system



kubectl create -f dashboard-ClusterRoleBinding.yaml

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

nodePort range 1-65535



nano /etc/kubernetes/manifests/kube-apiserver.yaml

#add command

--service-node-port-range=1-65535

kubeadm reset


sudo kubeadm reset 
rm -rf .kube

sudo sysctl net.bridge.bridge-nf-call-iptables=1

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

kubectl get nodes
kubectl get pods --all-namespaces

kubectl taint nodes --all node-role.kubernetes.io/master-

kubectl create secret generic kubernetes-dashboard-certs --from-file=certs -n kube-system
kubectl create -f kubernetes-dashboard.yaml

## This login token
kubectl create -f dashboard-adminuser.yaml
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

kubectl create -f dashboard-ClusterRoleBinding.yaml
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')

nano /etc/kubernetes/manifests/kube-apiserver.yaml
#add command
--service-node-port-range=1-65535

... follow up step


kubeadm update



kubeadm upgrade plan

kubeadm upgrade apply

kubeadm command



clear && for p in $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name); do kubectl logs --namespace=kube-system $p; done

kubectl edit cm coredns -n kube-system


coreDNS no response


coreDNS error

coreDNS work correct


How to fix? Only way is reboot OS.

1. coreDNS error 2. reboot os 3.get coreDNS work correct

[轉]Kubernetes 的失敗案例

https://blog.gslin.org/archives/2019/01/30/8707/kubernetes-%E7%9A%84%E5%A4%B1%E6%95%97%E6%A1%88%E4%BE%8B/