Last active
May 17, 2019 06:36
-
-
Save ziozzang/eeaed13cf2f01234fa5b97bdaa214446 to your computer and use it in GitHub Desktop.
K3s-as-docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| MASTER_IP="10.1.2.96" | |
| HOSTNAME=`hostname` | |
| CA_FILE="/opt/k3s-master/output/ca-certificates.crt" | |
| TOKEN=`cat /opt/k3s-master/data/server/node-token` | |
| WORK_DIRS="/opt/${HOSTNAME}" | |
| mkdir -p ${WORK_DIRS} || true | |
| cp -f ${CA_FILE} ${WORK_DIRS}/ | |
| chmod 666 ${WORK_DIRS}/ca-certificates.crt | |
| docker rm -f ${HOSTNAME} | |
| docker run -d \ | |
| --restart=always \ | |
| --net=host \ | |
| --name=${HOSTNAME} \ | |
| -v ${WORK_DIRS}/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt \ | |
| -v ${WORK_DIRS}/data:/var/lib/rancher/k3s \ | |
| -v ${WORK_DIRS}/cni:/var/lib/cni \ | |
| -v ${WORK_DIRS}/log:/var/log \ | |
| --tmpfs /run \ | |
| --tmpfs /var/run \ | |
| --privileged \ | |
| rancher/k3s:v0.5.0 \ | |
| agent --server "${MASTER_URL}" --cluster-secret "somethingtotallyrandom" --token "${TOKEN}" | |
| #K3S_CLUSTER_SECRET=somethingtotallyrandom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -x | |
| docker rm -f k3s-master | |
| docker run -d --restart=always \ | |
| --name=k3s-master \ | |
| --net=host \ | |
| -e K3S_CLUSTER_SECRET=somethingtotallyrandom \ | |
| -e K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml \ | |
| -e K3S_KUBECONFIG_MODE=666 \ | |
| -v ${WORK_DIRS}/data:/var/lib/rancher/k3s \ | |
| -v ${WORK_DIRS}/cni:/var/lib/cni \ | |
| -v ${WORK_DIRS}/log:/var/log \ | |
| -v ${WORK_DIRS}/output:/output \ | |
| rancher/k3s:v0.5.0 server --disable-agent | |
| #-p 6443:6443 | |
| # Wait until container up. | |
| #while [[ "$(curl -k -s -o /dev/null -w ''%{http_code}'' localhost:6433)" != "401" ]]; do sleep 5; done | |
| sleep 10 | |
| # Set-up kubectl | |
| mkdir -p ~/.kube || true | |
| cat ${WORK_DIRS}/output/kubeconfig.yaml > ~/.kube/config | |
| TOKEN=`cat ${WORK_DIRS}/data/server/node-token` | |
| # Generate CERT (for Selfsigned CA) | |
| docker exec -it k3s-master cat /etc/ssl/certs/ca-certificates.crt > /opt/k3s-master/output/ca-certificates.crt | |
| #> Add master cert. | |
| #cat >> /opt/k3s-master/output/ca-certificates.crt <<EOF | |
| #-----BEGIN CERTIFICATE----- | |
| #foo----- | |
| #-----END CERTIFICATE----- | |
| #EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -x | |
| #################################################################### | |
| # Kubernetes PV storage configuration (example: NFS) | |
| # - Code by Jioh L. Jung | |
| #################################################################### | |
| # Code is for Use local storage as K8S storage | |
| # mabe just fit for 'NFS mounted storage' | |
| #- Generate Local Storage | |
| rm -rf ${PV_STORAGE_LOCAL_PATH} | |
| mkdir -p ${PV_STORAGE_LOCAL_PATH} | |
| cat << EFF | kubectl create -f - | |
| kind: StorageClass | |
| apiVersion: storage.k8s.io/v1 | |
| metadata: | |
| namespace: default | |
| name: ${PV_STORAGE_NAME} | |
| annotations: | |
| storageclass.kubernetes.io/is-default-class: "true" | |
| provisioner: kubernetes.io/no-provisioner | |
| volumeBindingMode: WaitForFirstConsumer | |
| EFF | |
| # Create Basic Storage Directories | |
| #- 020 means total count of storage | |
| for i in {001..040}; do | |
| mkdir -p "${PV_STORAGE_LOCAL_PATH}/${i}" | |
| chmod 777 "${PV_STORAGE_LOCAL_PATH}/${i}" | |
| cat << EFF | kubectl create -f - | |
| apiVersion: v1 | |
| kind: PersistentVolume | |
| metadata: | |
| name: ${PV_STORAGE_NAME}-${i} | |
| labels: | |
| types: hdd | |
| spec: | |
| storageClassName: ${PV_STORAGE_NAME} | |
| capacity: | |
| storage: ${PV_STORAGE_MAX_SIZE} | |
| volumeMode: Filesystem | |
| accessModes: | |
| - ReadWriteOnce | |
| - ReadOnlyMany | |
| - ReadWriteMany | |
| persistentVolumeReclaimPolicy: Recycle | |
| hostPath: | |
| path: "${PV_STORAGE_LOCAL_PATH}/${i}" | |
| EFF | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| DOCKER_IMAGES="rancher/rancher:latest" | |
| docker pull ${DOCKER_IMAGES} | |
| docker rm -f rancher-master | |
| docker run \ | |
| -d --name=rancher-master \ | |
| --restart=always \ | |
| -v /opt/rancher/data:/var/lib/rancher \ | |
| -p 38080:80 -p 38443:443 \ | |
| ${DOCKER_IMAGES} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| export PV_STORAGE_LOCAL_PATH="/NAS/k3s-storage/blob/" | |
| export PV_STORAGE_NAME="pvl-nas-storage" | |
| export PV_STORAGE_MAX_SIZE="100Gi" | |
| bash ./local.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment