UNCLASSIFIED - NO CUI
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bigbang
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Big Bang
bigbang
Commits
124b73f7
Commit
124b73f7
authored
2 years ago
by
Micah Nagel
Browse files
Options
Downloads
Patches
Plain Diff
k3d dev script: add volumes to support twistlock defenders
parent
6f982d6f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2019
k3d dev script: add volumes to support twistlock defenders
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/assets/scripts/developer/k3d-dev.sh
+46
-39
46 additions, 39 deletions
docs/assets/scripts/developer/k3d-dev.sh
with
46 additions
and
39 deletions
docs/assets/scripts/developer/k3d-dev.sh
+
46
−
39
View file @
124b73f7
...
...
@@ -115,7 +115,7 @@ while [ -n "$1" ]; do # while loop starts
echo
" -b use BIG M5 instance. Default is t3.2xlarge"
echo
" -p use private IP for security group and k3d cluster"
echo
" -m create k3d cluster with metalLB"
echo
" -d destroy related AWS resources"
echo
" -d destroy related AWS resources"
echo
" -h output help"
exit
0
;;
...
...
@@ -319,7 +319,7 @@ ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${PublicIP}"
echo
"ssh init"
# this is a do-nothing remote ssh command just to initialize ssh and make sure that the connection is working
until
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"hostname"
;
do
until
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"hostname"
;
do
sleep
5
echo
"Retry ssh command.."
done
...
...
@@ -331,67 +331,74 @@ echo
echo
echo
"starting instance config"
echo
"Machine config"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo sysctl -w vm.max_map_count=524288"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c
\"
echo 'vm.max_map_count=524288' > /etc/sysctl.d/vm-max_map_count.conf
\"
"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c
\"
echo 'fs.file-max=131072' > /etc/sysctl.d/fs-file-max.conf
\"
"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c 'sysctl -p'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c 'ulimit -n 131072'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c 'ulimit -u 8192'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c 'modprobe xt_REDIRECT'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c 'modprobe xt_owner'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c 'modprobe xt_statistic'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo sysctl -w vm.max_map_count=524288"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c
\"
echo 'vm.max_map_count=524288' > /etc/sysctl.d/vm-max_map_count.conf
\"
"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c
\"
echo 'fs.file-max=131072' > /etc/sysctl.d/fs-file-max.conf
\"
"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c 'sysctl -p'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c 'ulimit -n 131072'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c 'ulimit -u 8192'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c 'modprobe xt_REDIRECT'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c 'modprobe xt_owner'"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c 'modprobe xt_statistic'"
echo
"Instance will automatically terminate at 08:00 UTC"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo bash -c
\"
echo '0 8 * * * /usr/sbin/shutdown -h now' | crontab -
\"
"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo bash -c
\"
echo '0 8 * * * /usr/sbin/shutdown -h now' | crontab -
\"
"
echo
echo
echo
"installing packages"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo apt remove -y docker docker-engine docker.io containerd runc"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo apt -y update"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo apt remove -y docker docker-engine docker.io containerd runc"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo apt -y update"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common"
echo
echo
# Add the Docker repository, we are installing from Docker and not the Ubuntu APT repo.
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo apt-key fingerprint 0EBFCD88"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
'sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
'sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
'echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo apt-key fingerprint 0EBFCD88"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
'sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
'sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
'echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list'
echo
echo
# Install Docker
echo
"install Docker"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io kubectl jq tree vim"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io kubectl jq tree vim"
echo
echo
# Add your base user to the Docker group so that you do not need sudo to run docker commands
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"sudo usermod -aG docker ubuntu"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"sudo usermod -aG docker ubuntu"
echo
echo
# install k3d on instance
echo
"Installing k3d on instance"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"wget -q -O - https://raw.githubusercontent.com/rancher/k3d/main/install.sh | TAG=v5.4.4 bash"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"wget -q -O - https://raw.githubusercontent.com/rancher/k3d/main/install.sh | TAG=v5.4.4 bash"
echo
echo
"k3d version"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"k3d version"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"k3d version"
echo
echo
"creating k3d cluster"
# Shared settings across all options
k3d_command
=
"k3d cluster create --servers 1 --agents 3 --volume /etc/machine-id:/etc/machine-id@server:*
\;
agent:* --k3s-arg
\"
--disable=traefik@server:0
\"
--k3s-arg
\"
--disable=metrics-server@server:0
\"
--port 80:80@loadbalancer --port 443:443@loadbalancer --api-port 6443"
# Shared k3d settings across all options
# 1 server, 3 agents
k3d_command
=
"k3d cluster create --servers 1 --agents 3"
# Volumes to support Twistlock defenders
k3d_command+
=
" -v /etc:/etc@server:*
\;
agent:* -v /dev/log:/dev/log@server:*
\;
agent:* -v /run/systemd/private:/run/systemd/private@server:*
\;
agent:*"
# Disable traefik and metrics-server
k3d_command+
=
" --k3s-arg
\"
--disable=traefik@server:0
\"
--k3s-arg
\"
--disable=metrics-server@server:0
\"
"
# Port mappings to support Istio ingress + API access
k3d_command+
=
" --port 80:80@loadbalancer --port 443:443@loadbalancer --api-port 6443"
# Add MetalLB specific k3d config
if
[[
"
$METAL_LB
"
==
true
]]
;
then
# create docker network for k3d cluster
echo
"creating docker network for k3d cluster"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"docker network create k3d-network --driver=bridge --subnet=172.20.0.0/16 --gateway 172.20.0.1"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"docker network create k3d-network --driver=bridge --subnet=172.20.0.0/16 --gateway 172.20.0.1"
k3d_command+
=
" --k3s-arg
\"
--disable=servicelb@server:0
\"
--network k3d-network"
fi
...
...
@@ -405,17 +412,17 @@ else
fi
# Create k3d cluster
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"
${
k3d_command
}
"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"kubectl config use-context k3d-k3s-default"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"kubectl cluster-info"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"
${
k3d_command
}
"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"kubectl config use-context k3d-k3s-default"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"kubectl cluster-info"
# Handle MetalLB cluster resource creation
if
[[
"
$METAL_LB
"
==
true
]]
;
then
echo
"installing MetalLB"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"kubectl create -f https://raw.githubusercontent.com/metallb/metallb/v0.10.2/manifests/namespace.yaml"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"kubectl create -f https://raw.githubusercontent.com/metallb/metallb/v0.10.2/manifests/metallb.yaml"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"kubectl create -f https://raw.githubusercontent.com/metallb/metallb/v0.10.2/manifests/namespace.yaml"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"kubectl create -f https://raw.githubusercontent.com/metallb/metallb/v0.10.2/manifests/metallb.yaml"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
<<-
'
ENDSSH
'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
<<-
'
ENDSSH
'
#run this command on remote
cat << EOF > metallb-config.yaml
apiVersion: v1
...
...
@@ -433,11 +440,11 @@ if [[ "$METAL_LB" == true ]]; then
EOF
ENDSSH
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
"kubectl create -f metallb-config.yaml"
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
"kubectl create -f metallb-config.yaml"
fi
echo
"copying kubeconfig to workstation..."
scp
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
:/home/ubuntu/.kube/config ~/.kube/
${
AWSUSERNAME
}
-dev-config
scp
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
:/home/ubuntu/.kube/config ~/.kube/
${
AWSUSERNAME
}
-dev-config
if
[[
"
$PRIVATE_IP
"
==
true
]]
;
then
$sed_gsed
-i
"s/0
\.
0
\.
0
\.
0/
${
PrivateIP
}
/g"
~/.kube/
${
AWSUSERNAME
}
-dev-config
else
# default is to use public ip
...
...
@@ -446,13 +453,13 @@ fi
# add tools
echo
Installing kubectl...
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
'curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
'sudo mv /home/ubuntu/kubectl /usr/local/bin/'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
'sudo chmod +x /usr/local/bin/kubectl'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
'curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
'sudo mv /home/ubuntu/kubectl /usr/local/bin/'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
'sudo chmod +x /usr/local/bin/kubectl'
if
[[
"
$METAL_LB
"
==
true
]]
;
then
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no ubuntu@
${
PublicIP
}
<<-
'
ENDSSH
'
ssh
-i
~/.ssh/
${
KeyName
}
.pem
-o
StrictHostKeyChecking
=
no
-o
IdentitiesOnly
=
yes
ubuntu@
${
PublicIP
}
<<-
'
ENDSSH
'
# run this command on remote
# fix /etc/hosts for new cluster
sudo sed -i '/bigbang.dev/d' /etc/hosts
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment