Skip to content

Commit

Permalink
chore: Remove k3d integration (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarojasm95 authored Jan 22, 2025
1 parent 8a268f5 commit e1aabb4
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 152 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ ARG ISTIO_VERSION=1.20.8
RUN curl -L https://istio.io/downloadIstio | ISTIO_VERSION="$ISTIO_VERSION" sh - && \
mv /istio-$ISTIO_VERSION/bin/istioctl /usr/local/bin/istioctl

ARG K3D_VERSION=4.4.8
RUN curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | TAG=v$K3D_VERSION bash

RUN curl -fsSL https://raw.githubusercontent.com/ahmetb/kubectl-aliases/master/.kubectl_aliases -o /etc/profile.d/kubectl_aliases.sh && \
chmod +x /etc/profile.d/kubectl_aliases.sh

Expand Down
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## What is Aladdin?

Inspired by the Genie of the Lamp, Aladdin is a command line tool built by Fivestars to simplify kubernetes operations for clusters management and application development. We have done this by combining several command line tools including kops, k3d, docker, kubectl, helm, awscli, and git.
Inspired by the Genie of the Lamp, Aladdin is a command line tool built by Fivestars to simplify kubernetes operations for clusters management and application development. We have done this by combining several command line tools including kops, docker, kubectl, helm, awscli, and git.

Use aladdin to:
- Create and manage an aws kubernetes cluster
Expand All @@ -17,7 +17,6 @@ The host component is responsible for:
- Parsing command line options
- Running any commands to be executed on the host machine
- Checking and warning about any missing dependencies or installing the dependency in `~/.aladdin/bin` if possible
- Starting k3d (make sure your docker engine is running before running aladdin!)
- Pulling the aladdin image
- Running the aladdin docker container (the container component)

Expand Down Expand Up @@ -74,12 +73,6 @@ Then run:
aladdin config set manage.software_dependencies false
```

#### k3d
aladdin uses k3d to support local development

### Local Cluster Resource Configuration
Currently, you can configure cpu, memory, and disk by going to your docker desktop UI, going to preferences, and then going to resources. The recommended configuration is 2 CPUs, 8GB memory, and 60GB disk.

## Creating and managing an aws kubernetes cluster
This is all encapsulated in the [aladdin cluster command](./docs/cluster_cmd.md)

Expand Down Expand Up @@ -131,7 +124,6 @@ We have several aladdin commands used for development and deployment. Note that
- `aladdin create-namespace` create the namespace you pass in.
- `aladdin delete-namespace` delete the namespace you pass in _after_ removing all the helm packages on that namespace.
- `aladdin get-dashboard-url` will output the url of your cluster's dashboard assuming it is installed.
- `aladdin host` give instructions to update your local /etc/hosts file for k3d ingress compatibility.
- For a complete list of aladdin commands, run `aladdin -h`.

## Optional arguments to aladdin
Expand Down Expand Up @@ -227,7 +219,7 @@ Aladdin supports an ingress per namespace feature. This is off by default. We re
"ingress_name": "ingress"
}
```
The "namespace_init" field tells aladdin to install the ingress-nginx project on namespace creation. This will be needed on remote clusters, but not on LOCAL, since k3d comes with that out of the box.
The "namespace_init" field tells aladdin to install the ingress-nginx project on namespace creation. This will be needed on remote clusters, but not on LOCAL.
The "ingress_info" field tells aladdin how to sync your ingress. Services installed on a cluster with this feature will want to have their service type set to `NodePort` rather than `LoadBalancer`. This is most easily done by setting it in the values.yaml in your cluster's directory in aladdin config, i.e. adding this:
```yaml
service:
Expand Down
19 changes: 2 additions & 17 deletions aladdin-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,16 @@ function environment_init() {
fi

if "$IS_LOCAL"; then
local cluster_provider="k3d"
local cluster_provider="none"
if [[ -f "$HOME/.aladdin/config/config.json" ]]; then
cluster_provider=$(jq -r '.local_cluster_provider // "k3d"' $HOME/.aladdin/config/config.json)
cluster_provider=$(jq -r '.local_cluster_provider // "none"' $HOME/.aladdin/config/config.json)
fi
if [[ "$cluster_provider" == "rancher-desktop" ]]; then
mkdir -p $HOME/.kube/
sed 's/127.0.0.1/172.17.0.1/g' $HOME/.kube_local/config > $HOME/.kube/config
kubectl config set-context "rancher-desktop" --cluster "rancher-desktop" --namespace="$NAMESPACE" --user "rancher-desktop"
kubectl config use-context "rancher-desktop"
fi
if [[ "$cluster_provider" == "k3d" ]]; then
K3D_SERVICE_PORT=8081 # default value
if [[ -f "$HOME/.aladdin/config/config.json" ]]; then
K3D_SERVICE_PORT=$(jq -r '.k3d.service_port // 8081' $HOME/.aladdin/config/config.json)
fi
# Get k3d api port
K3D_API_PORT=6550 # default value
if [[ -f "$HOME/.aladdin/config/config.json" ]]; then
K3D_API_PORT=$(jq -r '.k3d.api_port // 6550' $HOME/.aladdin/config/config.json)
fi
mkdir -p $HOME/.kube/
sed "s;https://0.0.0.0:$K3D_API_PORT;https://$HOST_ADDR:$K3D_API_PORT;g" $HOME/.kube_local/config > $HOME/.kube/config
kubectl config set-context "$NAMESPACE.k3d-$CLUSTER_NAME" --cluster "k3d-$CLUSTER_NAME" --namespace="$NAMESPACE" --user "admin@k3d-$CLUSTER_NAME"
kubectl config use-context "$NAMESPACE.k3d-$CLUSTER_NAME"
fi
else
_get_kubeconfig
fi
Expand Down
48 changes: 2 additions & 46 deletions aladdin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function check_cluster_alias() {
}

function get_config_variables() {
LOCAL_CLUSTER_PROVIDER="k3d"
LOCAL_CLUSTER_PROVIDER="none"
if [[ -f "$HOME/.aladdin/config/config.json" ]]; then
LOCAL_CLUSTER_PROVIDER=$(jq -r '.local_cluster_provider // "k3d"' $HOME/.aladdin/config/config.json)
LOCAL_CLUSTER_PROVIDER=$(jq -r '.local_cluster_provider // "none"' $HOME/.aladdin/config/config.json)
fi
}

Expand Down Expand Up @@ -79,50 +79,6 @@ function check_and_handle_init() {
if "$ALADDIN_MANAGE_SOFTWARE_DEPENDENCIES"; then
"$SCRIPT_DIR"/infra_k8s_check.sh $infra_k8s_check_args
fi
if "$IS_LOCAL" && [[ "$LOCAL_CLUSTER_PROVIDER" == "k3d" ]]; then
check_or_start_k3d
fi
}

function _start_k3d() {
# Get k3d service port
K3D_SERVICE_PORT=8081 # default value
if [[ -f "$HOME/.aladdin/config/config.json" ]]; then
K3D_SERVICE_PORT=$(jq -r '.k3d.service_port // 8081' $HOME/.aladdin/config/config.json)
fi
# Get k3d api port
K3D_API_PORT=6550 # default value
if [[ -f "$HOME/.aladdin/config/config.json" ]]; then
K3D_API_PORT=$(jq -r '.k3d.api_port // 6550' $HOME/.aladdin/config/config.json)
fi
# start k3d cluster
k3d cluster create LOCAL \
--api-port "$K3D_API_PORT" \
-p "$K3D_SERVICE_PORT:80@loadbalancer" \
--image "rancher/k3s:v$KUBERNETES_VERSION-k3s1" \
--k3s-server-arg "--tls-san=$HOST_ADDR" \
`# these last two are for compatibility with newer linux kernels` \
`# https://k3d.io/faq/faq/#solved-nodes-fail-to-start-or-get-stuck-in-notready-state-with-log-nf_conntrack_max-permission-denied` \
`# https://github.com/rancher/k3d/issues/607` \
--k3s-server-arg "--kube-proxy-arg=conntrack-max-per-core=0" \
--k3s-agent-arg "--kube-proxy-arg=conntrack-max-per-core=0"
}

function check_or_start_k3d() {
if docker info | grep "Cgroup Version: 2" > /dev/null && [[ "$KUBERNETES_VERSION" == "1.19.7" ]]; then
echoerr "ERROR: Current version of k3d is not compatible with cgroups v2"
echoerr "ERROR: If using Docker Desktop please downgrade to v4.2.0"
fi
if ! k3d cluster list | grep LOCAL > /dev/null; then
echoerr "Starting k3d LOCAL cluster... (this will take a moment)"
_start_k3d
else
if ! kubectl version | grep "Server" | grep "$KUBERNETES_VERSION" > /dev/null; then
echoerr "k3d detected on the incorrect version, stopping and restarting"
k3d cluster delete LOCAL > /dev/null
check_or_start_k3d
fi
fi
}

function set_cluster_helper_vars() {
Expand Down
4 changes: 2 additions & 2 deletions aladdin/bash/container/test-local/test-local
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function test_local {
function usage {
cat <<-EOF
usage: aladdin test-local [-h]
optional arguments:
-h, --help show this help message and exit
EOF
Expand All @@ -38,7 +38,7 @@ if [[ $# -eq 0 ]]; then
if $IS_LOCAL && $IS_TESTING; then
test_local
else
echo >&2 "aladdin test-local should only be called on a local testing k3d cluster"
echo >&2 "aladdin test-local should only be called on a local testing cluster"
fi
elif [[ "$1" == "-h" || "$1" == "--help" ]]; then
usage
Expand Down
4 changes: 2 additions & 2 deletions aladdin/bash_help.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"help": "Show the history of a helm release"
},
"host": {
"help": "Give instructions to update local /etc/hosts file for k3d ingress compatibility"
"help": "Give instructions to update local /etc/hosts file for local ingress compatibility"
},
"load-images": {
"help": "Import local images"
Expand All @@ -39,7 +39,7 @@
"help": "Export images locally"
},
"test-local": {
"help": "Test aladdin local commands using a test k3d cluster"
"help": "Test aladdin local commands using a test cluster"
},
"test-remote": {
"help": "Test aladdin remote commands on a remote test cluster"
Expand Down
7 changes: 1 addition & 6 deletions aladdin/commands/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import argparse

from aladdin.lib.project_conf import ProjectConf
from aladdin.lib.arg_tools import container_command
from aladdin.lib.k8s.k3d import K3d
from aladdin.lib.project_conf import ProjectConf


def parse_args(sub_parser):
Expand All @@ -20,9 +19,5 @@ def build_args(args):
@container_command
def build(build_args):
tag = "local"
k3d = K3d()
pc = ProjectConf()
pc.build_docker(env={"HASH": tag}, build_args=build_args)
images = pc.get_docker_images()
if images:
k3d.import_images([f"{image}:{tag}" for image in images])
14 changes: 8 additions & 6 deletions aladdin/lib/k8s/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def build_ingress(services, dns_suffix, dual_dns_prefix_annotation_name, ingress
)
# A little bit of a hack to have the ingress put the port:443 entries before the port:80 entries,
# so that the port:80 entries take precedence if the service name is the same. Without this
# we get ssl errors when accessing services behind the ingress locally because of k3d internals
# we get ssl errors when accessing services behind the ingress locally
service_tuples = sorted(service_tuples, key=lambda x: x[1], reverse=True)
for dns_prefix, port, service in service_tuples:
ingress_rule = client.V1IngressRule()
Expand All @@ -53,11 +53,13 @@ def build_ingress(services, dns_suffix, dual_dns_prefix_annotation_name, ingress
name=service.metadata.name,
)
)
ingress_rule.http = client.V1HTTPIngressRuleValue([
client.V1HTTPIngressPath(
path="/", backend=backend, path_type="ImplementationSpecific"
)
])
ingress_rule.http = client.V1HTTPIngressRuleValue(
[
client.V1HTTPIngressPath(
path="/", backend=backend, path_type="ImplementationSpecific"
)
]
)

ingress.spec.rules.append(ingress_rule)

Expand Down
8 changes: 0 additions & 8 deletions aladdin/lib/k8s/k3d.py

This file was deleted.

3 changes: 0 additions & 3 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Troubleshooting
You may want to first try:
- Rerunning your aladdin command with `--init` flag
- Restarting your LOCAL cluster via `k3d cluster delete LOCAL && aladdin --init` and then rerunning your command
## Specific Issues
### InvalidSignatureException
Fix this by restarting your LOCAL cluster via `k3d cluster delete LOCAL && aladdin --init` and then rerunning your command
### Problems with git processing during aladdin deploy or publish
If your error is something like this:
```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "aladdin"
version = "1.29.8.10"
version = "1.29.8.11"
description = ""
authors = ["Fivestars <dev@fivestars.com>"]
include = [
Expand Down
48 changes: 0 additions & 48 deletions scripts/infra_k8s_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ set -eu -o pipefail

# To force the script to do the full check, use the parameter '--force'

#- from : https://github.com/rancher/k3d/releases
VERSION_K3D="4.4.8"
#- from : https://github.com/kubernetes/kubernetes/releases
VERSION_KUBECTL="1.27.13"
#- from : https://github.com/kubernetes/helm/releases
Expand All @@ -18,8 +16,6 @@ VERSION_HELM="3.12.0"

# This script is meant to check and test the necessary tools for using the infra tools.
#
# To run k3d :
# - k3d
# - kubectl
# - helm

Expand Down Expand Up @@ -284,26 +280,6 @@ function install_wget_win(){ eval $install_cmd wget >/dev/null 2>/dev/null ; }
function install_wget_mac(){ eval $install_cmd wget >/dev/null 2>/dev/null ; }
function install_wget_ubuntu(){ eval $install_cmd wget >/dev/null 2>/dev/null ; }


function check_k3d(){ version "$ALADDIN_BIN/k3d version" "$VERSION_K3D" ;}

function install_k3d() {
curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | K3D_INSTALL_DIR=$ALADDIN_BIN TAG=v${VERSION_K3D} USE_SUDO=false bash
}

function install_k3d_win(){
install_k3d
}
function install_k3d_mac(){
install_k3d
}
function install_k3d_alpine(){
install_k3d
}
function install_k3d_ubuntu(){
install_k3d
}

function check_kubectl(){ version "$ALADDIN_BIN/kubectl version --client" "Client.*v$VERSION_KUBECTL" ; }
function install_kubectl_win(){
typeset url="https://dl.k8s.io/v${VERSION_KUBECTL}/kubernetes-client-windows-amd64.tar.gz"
Expand Down Expand Up @@ -353,28 +329,15 @@ function install_git_alpine(){ eval $install_cmd git >/dev/null 2>/dev/null ; }
function install_git_ubuntu(){ eval $install_cmd git >/dev/null 2>/dev/null ; }
function check_git(){ has_prog git ; }

function install_python3_win(){ eval $install_cmd python3 >/dev/null 2>/dev/null ; }
function install_python3_mac(){ eval $install_cmd python3 >/dev/null 2>/dev/null ; }
function install_python3_alpine(){ eval $install_cmd python3 >/dev/null 2>/dev/null ; }
function install_python3_ubuntu(){ eval $install_cmd python3 >/dev/null 2>/dev/null ; }
function check_python3(){ has_prog python3 ; }

function install_awscli_win(){ python3 -m pip install --upgrade awscli >/dev/null 2>/dev/null ; }
function install_awscli_mac(){ python3 -m pip install --upgrade awscli >/dev/null 2>/dev/null ; }
function install_awscli_alpine(){ python3 -m pip install --upgrade awscli >/dev/null 2>/dev/null ; }
function install_awscli_ubuntu(){ pip install --upgrade awscli >/dev/null 2>/dev/null ; }
function check_awscli(){ has_prog aws ; }

function check_openssl(){ openssl version; }
function install_openssl_alpine(){ eval $install_cmd ca-certificates && update-ca-certificates && eval $install_cmd ca-certificates openssl; }
function install_openssl_ubuntu(){ eval $install_cmd ca-certificates && update-ca-certificates && eval $install_cmd ca-certificates openssl; }

function install_jq_alpine(){ eval $install_cmd jq ; }
function install_jq_ubuntu(){ eval $install_cmd jq ; }

function install_pip_ubuntu(){ eval $install_cmd python-pip ; }

function check_pip(){ has_prog pip; }
function check_socat(){ has_prog socat ; }

function main(){
Expand All @@ -389,11 +352,9 @@ function main(){
check_and_warn "apt-cyg " aptcyg
check_and_warn "unzip " unzip
check_and_warn "wget " wget
check_and_install "k3d ($VERSION_K3D) " k3d
check_and_install "kubectl ($VERSION_KUBECTL) " kubectl
check_and_install "helm ($VERSION_HELM) " helm
check_and_warn "jq " jq
#check_and_warn "git " git
check_and_warn "python3 " python3
check_and_warn "aws-cli " awscli

Expand All @@ -404,11 +365,9 @@ function main(){
mac)
check_and_warn "brew " brew
check_and_warn "wget " wget
check_and_install "k3d ($VERSION_K3D) " k3d
check_and_install "kubectl ($VERSION_KUBECTL) " kubectl
check_and_install "helm ($VERSION_HELM) " helm
check_and_warn "jq " jq
#check_and_warn "git " git
check_and_warn "python3 " python3
check_and_warn "aws-cli " awscli

Expand All @@ -418,11 +377,9 @@ function main(){
alpine)
check_and_warn "openssl " openssl
check_and_warn "wget " wget
check_and_install "k3d ($VERSION_K3D) " k3d
check_and_install "kubectl ($VERSION_KUBECTL) " kubectl
check_and_install "helm ($VERSION_HELM) " helm
check_and_warn "jq " jq
#check_and_warn "git " git
check_and_warn "python3 " python3
check_and_warn "aws-cli " awscli

Expand All @@ -431,15 +388,10 @@ function main(){

;;
ubuntu)
#check_and_install "openssl " openssl
check_and_warn "wget " wget
check_and_install "k3d ($VERSION_K3D) " k3d
check_and_install "kubectl ($VERSION_KUBECTL) " kubectl
check_and_install "helm ($VERSION_HELM) " helm
check_and_warn "jq " jq
#check_and_warn "git " git
check_and_warn "python-pip " pip
check_and_warn "python3 " python3
check_and_warn "aws-cli " awscli

# Only validate the script install at the end
Expand Down

0 comments on commit e1aabb4

Please sign in to comment.