Skip to content

Commit

Permalink
Pre Pull
Browse files Browse the repository at this point in the history
  • Loading branch information
Sellto committed Mar 9, 2019
1 parent 1c925c5 commit 7667bc4
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 169 deletions.
40 changes: 36 additions & 4 deletions agent.sh → install_k3s.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ EOF
fi

chmod 755 $TMPBIN
info Installing k3s to /usr/local/bin/k3s



info Installing k3s to /usr/local/bin/k3s
$SUDO chown root:root $TMPBIN
$SUDO mv -f $TMPBIN /usr/local/bin/k3s

Expand All @@ -131,8 +133,38 @@ EOF
$SUDO ln -s k3s /usr/local/bin/crictl
fi

info Creating configuration file

if [$1 == "agent"]
$SUDO mkdir -p /etc/k3s/
$SUDO tee /etc/k3s/agent-conf.yml >/dev/null <<EOF
token: #Token to use for authentication [$K3S_TOKEN]
server: #Server to connect to [$K3S_URL]
data-dir: #Folder to hold state (default: "/var/lib/rancher/k3s")
docker: "no" #Use docker instead of containerd
no-flannel: "no" #Disable embedded flannel
cluster-secret : #Shared secret used to bootstrap a cluster [$K3S_CLUSTER_SECRET]
node-name : #Node name [$K3S_NODE_NAME]
node-ip: #IP address to advertise for node
EOF
fi
if [$1 == "server"]
$SUDO mkdir -p /etc/k3s/
$SUDO tee /etc/k3s/server-conf.yml >/dev/null <<EOF
token: #Token to use for authentication [$K3S_TOKEN]
server: #Server to connect to [$K3S_URL]
data-dir: #Folder to hold state (default: "/var/lib/rancher/k3s")
docker: "no" #Use docker instead of containerd
no-flannel: "no" #Disable embedded flannel
cluster-secret : #Shared secret used to bootstrap a cluster [$K3S_CLUSTER_SECRET]
node-name : #Node name [$K3S_NODE_NAME]
node-ip: #IP address to advertise for node
EOF
fi


info systemd: Creating /etc/systemd/system/k3s.service
$SUDO tee /etc/systemd/system/k3s.service >/dev/null << "EOF"
$SUDO tee /etc/systemd/system/k3s.service >/dev/null <<EOF
[Unit]
Description=Lightweight Kubernetes
Documentation=https://k3s.io
Expand All @@ -141,7 +173,7 @@ After=network.target
[Service]
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/local/bin/k3s agent --server https://3.14.15.9:6443 --token K10669b9d21f2f6a6b2ce8588d4b40c1bff9fd893f51de84ea45d83637362e9280a::node:89c47074a57e171f7ca5fdf64a50eb56
ExecStartPre=source /usr/local/bin/k3s-starup $1
KillMode=process
Delegate=yes
LimitNOFILE=infinity
Expand All @@ -156,7 +188,7 @@ EOF
info systemd: Enabling k3s unit
$SUDO systemctl enable k3s.service >/dev/null
$SUDO systemctl daemon-reload >/dev/null

systemctl status k3s.service
info systemd: Starting k3s
$SUDO systemctl start k3s.service
else
Expand Down
Binary file added k3s-startup
Binary file not shown.
67 changes: 67 additions & 0 deletions k3s-startup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
//"fmt"
"log"
"io/ioutil"
"gopkg.in/yaml.v2"
"os/exec"
"os"
)

var boolOptions = []string{"no-flannel","docker","disable-agent"}

func stringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}


func getConf(file string) map[string]string {
conf := make(map[string]string)
var yamlFile []byte
yamlFile, err := ioutil.ReadFile(file)
if err != nil {
log.Printf("can't find the yaml file")
}
err = yaml.Unmarshal([]byte(yamlFile), &conf)
if err != nil {
log.Fatalf("check the yaml file format")
}
return conf
}

func constructCmd(mode string) exec.Cmd{
args := []string{"/usr/local/bin/k3s",mode}
for key,value := range getConf("/etc/k3s/"+mode+"-conf.yml") {
if stringInSlice(key,boolOptions) {
if value == "yes" {
args = append(args,"--"+key)
}
} else if value != "" {
args = append(args,"--"+key)
args = append(args,value)
}
}
cmd := exec.Cmd{}
cmd.Path= "/usr/local/bin/k3s"
cmd.Args = args
return cmd
}

func main() {
sleepcmd := exec.Command("sleep","10")
err := sleepcmd.Start()
if err != nil {
log.Fatal(err)
}
k3scmd := constructCmd(os.Args[1])
err = k3scmd.Start()
if err != nil {
log.Fatal(err)
}
}
165 changes: 0 additions & 165 deletions server.sh

This file was deleted.

8 changes: 8 additions & 0 deletions usr/local/bin/k3s/agent-conf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
token: #Token to use for authentication []
server: #Server to connect to []
data-dir: #Folder to hold state (default: "/var/lib/rancher/k3s")
docker: "no" #Use docker instead of containerd
no-flannel: "no" #Disable embedded flannel
cluster-secret : #Shared secret used to bootstrap a cluster []
node-name : #Node name []
node-ip: #IP address to advertise for node

0 comments on commit 7667bc4

Please sign in to comment.