Skip to content

Instantly share code, notes, and snippets.

@rmetzler
Forked from vfarcic/161-talos.sh
Created March 30, 2022 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmetzler/d2aefc8ecf3830e7c273495ef983d3ab to your computer and use it in GitHub Desktop.
Save rmetzler/d2aefc8ecf3830e7c273495ef983d3ab to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/c7cdfef142bd65cc744789d3c1e90170
###########################################
# Talos Linux: OS Designed For Kubernetes #
# https://youtu.be/iEFb2Zg4xUg #
###########################################
# Additional Info:
# - Talos Linux: https://www.talos.dev/
# - How To Create, Provision, And Operate Kubernetes With Cluster API (CAPI): https://youtu.be/8yUDUhZ6ako
#########
# Setup #
#########
# If using amd64 architecture
export ARCH=amd64
# If using arm64 architecture
export ARCH=arm64
curl -Lo /usr/local/bin/talosctl \
"https://github.com/talos-systems/talos/releases/latest/download/talosctl-$(uname -s | tr "[:upper:]" "[:lower:]")-$ARCH"
chmod +x /usr/local/bin/talosctl
curl https://github.com/talos-systems/talos/releases/latest/download/digital-ocean-amd64.tar.gz \
-L -o digital-ocean-amd64.tar.gz
tar -xzvf digital-ocean-amd64.tar.gz
rm digital-ocean-amd64.tar.gz
gzip disk.raw
rm disk.raw.gz
# Replace `[...]` with the region
export REGION=[...]
doctl compute image list
# Replace `[...]` with the image ID
export IMAGE_ID=[...]
doctl compute load-balancer create \
--region $REGION \
--name talos-demo \
--tag-name talos-demo-cp \
--health-check protocol:tcp,port:6443,check_interval_seconds:10,response_timeout_seconds:5,healthy_threshold:5,unhealthy_threshold:3 \
--forwarding-rules entry_protocol:tcp,entry_port:443,target_protocol:tcp,target_port:6443
# Replace `[...]` with the LB ID
export LB_ID=[...]
export LB_IP=$(\
doctl compute load-balancer get \
--format IP $LB_ID | tail -1)
echo $LB_IP
# Repeat the previous two commands if the output is empty (if the LB has not yet been created)
# Replace `[...]` with the public key
export PUBLIC_KEY=[...]
doctl compute ssh-key create devops-toolkit --public-key $PUBLIC_KEY
# Replace `[...]` with your SSH key fingerprint
export SSH_KEY_FINGERPRINT=[...]
######################################
# Create Nodes Based On Talos Images #
######################################
talosctl gen config \
talos-demo https://$LB_IP:443 \
--kubernetes-version 1.23.0
cat controlplane.yaml
cat worker.yaml
cat talosconfig
export CTRL_SIZE=s-2vcpu-4gb
export WORKER_SIZE=s-2vcpu-4gb
for N in 1 2 3
do
doctl compute droplet create \
--region $REGION \
--image $IMAGE_ID \
--size $CTRL_SIZE \
--enable-private-networking \
--tag-names talos-demo-cp \
--user-data-file controlplane.yaml \
--ssh-keys $SSH_KEY_FINGERPRINT \
talos-demo-cp-$N
doctl compute droplet create \
--region $REGION \
--image $IMAGE_ID \
--size $WORKER_SIZE \
--enable-private-networking \
--tag-names talos-demo-worker \
--user-data-file worker.yaml \
--ssh-keys $SSH_KEY_FINGERPRINT \
talos-demo-worker-$N
done
###########################################
# Bootstrap Kubernetes Cluster With Talos #
###########################################
for N in 1 2 3
do
export CP_IP_$N=$(doctl compute droplet get \
--format PublicIPv4 \
talos-demo-cp-$N \
| tail -1)
export WK_IP_$N=$(doctl compute droplet get \
--format PublicIPv4 \
talos-demo-worker-$N \
| tail -1)
done
talosctl --talosconfig talosconfig \
config endpoint $CP_IP_1
talosctl --talosconfig talosconfig \
config node $CP_IP_1
talosctl --talosconfig talosconfig \
bootstrap
talosctl --talosconfig talosconfig \
kubeconfig kubeconfig.yaml
kubectl --kubeconfig kubeconfig.yaml \
get nodes
##############################################
# Security, Predictability, And Evolvability #
##############################################
doctl compute ssh talos-demo-cp-2
doctl compute droplet create \
--region $REGION \
--image $IMAGE_ID \
--size $WORKER_SIZE \
--enable-private-networking \
--tag-names talos-demo-worker \
--user-data-file worker.yaml \
--ssh-keys $SSH_KEY_FINGERPRINT \
talos-demo-worker-4
kubectl --kubeconfig kubeconfig.yaml \
get nodes
doctl compute droplet delete \
talos-demo-worker-1 \
--force
kubectl --kubeconfig kubeconfig.yaml \
get nodes
talosctl \
--talosconfig talosconfig \
upgrade-k8s --to 1.23.1 \
--dry-run
talosctl \
--talosconfig talosconfig \
upgrade-k8s --to 1.23.1
kubectl --kubeconfig kubeconfig.yaml \
get nodes
kubectl --kubeconfig kubeconfig.yaml \
delete node talos-demo-worker-1
talosctl \
--talosconfig talosconfig \
upgrade-k8s --to 1.23.1
kubectl --kubeconfig kubeconfig.yaml \
get nodes
###################
# What's Missing? #
###################
kubectl --kubeconfig kubeconfig.yaml \
get services --all-namespaces
kubectl --kubeconfig kubeconfig.yaml \
get storageclasses
talosctl help
###########
# Destroy #
###########
for N in 1 2 3
do
doctl compute droplet \
delete talos-demo-cp-$N \
--force
done
for N in 2 3 4
do
doctl compute droplet \
delete talos-demo-worker-$N \
--force
done
doctl compute load-balancer \
delete $LB_ID \
--force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment