Skip to content

Instantly share code, notes, and snippets.

@icebob
Last active November 1, 2023 06:02
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save icebob/9c7cc01fbc9fb6883b5c3398e26fb3d5 to your computer and use it in GitHub Desktop.
Save icebob/9c7cc01fbc9fb6883b5c3398e26fb3d5 to your computer and use it in GitHub Desktop.
Start K3S Cluster on Docker
version: '3'
services:
server:
image: "rancher/k3s:latest"
command: server
tmpfs:
- /run
- /var/run
privileged: true
environment:
- K3S_TOKEN=token1234567890
- K3S_NODE_NAME=master
- K3S_KUBECONFIG_OUTPUT=/output/kube.config
- K3S_KUBECONFIG_MODE=666
volumes:
- k3s-server:/var/lib/rancher/k3s
- .:/output
ports:
- 6443:6443
- 80:80
- 443:443
- 8080:8080
restart: unless-stopped
worker1:
image: "rancher/k3s:latest"
tmpfs:
- /run
- /var/run
privileged: true
environment:
- K3S_URL=https://server:6443
- K3S_TOKEN=token1234567890
- K3S_NODE_NAME=worker-1
volumes:
- k3s-worker1:/var/lib/rancher/k3s
restart: unless-stopped
worker2:
image: "rancher/k3s:latest"
tmpfs:
- /run
- /var/run
privileged: true
environment:
- K3S_URL=https://server:6443
- K3S_TOKEN=token1234567890
- K3S_NODE_NAME=worker-2
volumes:
- k3s-worker2:/var/lib/rancher/k3s
restart: unless-stopped
volumes:
k3s-server: {}
k3s-worker1: {}
k3s-worker2: {}
@icebob
Copy link
Author

icebob commented Jan 7, 2020

Start K3s cluster

docker-compose up -d

Copy kube config

mkdir $HOME/.kube
cp ./kube.config $HOME/.kube/config

Install kubectl

curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version

Test cluster

kubectl get all --all-namespaces

Install K9s

wget https://github.com/derailed/k9s/releases/download/0.11.2/k9s_0.11.2_Linux_x86_64.tar.gz
tar -xvf k9s_0.11.2_Linux_x86_64.tar.gz
chmod +x ./k9s
sudo mv ./k9s /usr/local/bin/k9s

@icebob
Copy link
Author

icebob commented Jul 11, 2020

With Longhorn:

version: '3'

services:
  server:
    image: "rancher/k3s:latest"
    command: server
    tmpfs:
    - /run
    - /var/run
    privileged: true
    environment:
    - K3S_TOKEN=token1234567890
    - K3S_NODE_NAME=master
    - K3S_KUBECONFIG_OUTPUT=/output/kube.config
    - K3S_KUBECONFIG_MODE=666
    volumes:
    - k3s-server:/var/lib/rancher/k3s
    - k3s-server-lh:/var/lib/rancher/longhorn
    - .:/output
    ports:
    - 6443:6443
    - 80:80
    - 443:443
    - 8080:8080
    restart: unless-stopped

  worker1:
    image: "rancher/k3s:latest"
    tmpfs:
    - /run
    - /var/run
    privileged: true
    environment:
    - K3S_URL=https://server:6443
    - K3S_TOKEN=token1234567890
    - K3S_NODE_NAME=worker-1
    volumes:
    - k3s-worker1:/var/lib/rancher/k3s
    - k3s-worker1-lh:/var/lib/rancher/longhorn
    restart: unless-stopped

  worker2:
    image: "rancher/k3s:latest"
    tmpfs:
    - /run
    - /var/run
    privileged: true
    environment:
    - K3S_URL=https://server:6443
    - K3S_TOKEN=token1234567890
    - K3S_NODE_NAME=worker-2
    volumes:
    - k3s-worker2:/var/lib/rancher/k3s
    - k3s-worker2-lh:/var/lib/rancher/longhorn
    restart: unless-stopped

volumes:
  k3s-server: {}
  k3s-worker1: {}
  k3s-worker2: {}
  k3s-server-lh: {}
  k3s-worker1-lh: {}
  k3s-worker2-lh: {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment