Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install k3s on Azure Linux? #9724

Open
yockgen opened this issue Jul 9, 2024 · 5 comments
Open

How to install k3s on Azure Linux? #9724

yockgen opened this issue Jul 9, 2024 · 5 comments
Labels
question Further information is requested

Comments

@yockgen
Copy link

yockgen commented Jul 9, 2024

Ask your question or provide your feedback
How to install k3s on Azure Linux? Tried to use:

curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.24.10+k3s1" sh -s - server --cluster-init --disable-selinux

But dependencies failed to install, please see detail log below.

Screenshots
Actual logs as below:

yockgen@cbl-yockgen [ ~/k3s ]$ curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.24.10+k3s1" sh -s - server --cluster-init --disable-selinux
[INFO]  Using v1.24.10+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.24.10+k3s1/sha256sum-amd64.txt
[INFO]  Skipping binary downloaded, installed k3s matches hash
[INFO]  Finding available k3s-selinux versions
[ERROR]  Failed to apply container_runtime_exec_t to /usr/local/bin/k3s, please install:
    dnf install -y container-selinux
    dnf install -y https://rpm.rancher.io/k3s/stable/common/centos/9/noarch/

*** Dependencies - container-selinux not found ***

yockgen@cbl-yockgen [ ~/k3s ]$ sudo dnf install -y container-selinux
Last metadata expiration check: 0:21:47 ago on Tue Jul  9 06:41:48 2024.
No match for argument: container-selinux
Error: Unable to find a match: container-selinux

*** Dependencies - https://rpm.rancher.io/k3s/stable/common/centos/9/noarch/ not found ***

yockgen@cbl-yockgen [ ~/k3s ]$ sudo dnf install -y https://rpm.rancher.io/k3s/stable/common/centos/9/noarch/
Last metadata expiration check: 0:22:56 ago on Tue Jul  9 06:41:48 2024.
Cannot open /var/cache/dnf/commandline-a6d7f64df8682aeb/packages/.: Is a directory

Any guidance really appreciated.

@yockgen yockgen added the question Further information is requested label Jul 9, 2024
@zcobol
Copy link

zcobol commented Jul 10, 2024

CBL-Mariner already provides the k3s package:

root [ / ]# tdnf info k3s
Loaded plugin: tdnfrepogpgcheck
Name          : k3s
Arch          : x86_64
Epoch         : 0
Version       : 1.26.3
Release       : 2.cm2
Install Size  :  72.12M (75625221)
Download Size  :  65.59M (68778323)
Repo          : mariner-official-base
Summary       : Lightweight Kubernetes
URL           : https://k3s.io
License       : ASL 2.0
Description   : The certified Kubernetes distribution built for IoT & Edge computing.


Total Size:  72.12M (75625221)

@zcobol
Copy link

zcobol commented Jul 10, 2024

It works using the installation script also!

Output, using your command:

zcobol@mariner3 [ ~ ]$ curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.24.10+k3s1" sh -s - server --cluster-init --disable-selinux
[INFO]  Using v1.24.10+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.24.10+k3s1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.24.10+k3s1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Skipping installation of SELinux RPM
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO]  systemd: Starting k3s
zcobol@mariner3 [ ~ ]$ sudo kubectl version --output=yaml
clientVersion:
  buildDate: "2023-01-26T00:35:57Z"
  compiler: gc
  gitCommit: 546a94e9ae1c3be6f9c0dcde32a6e6672b035bc8
  gitTreeState: clean
  gitVersion: v1.24.10+k3s1
  goVersion: go1.19.5
  major: "1"
  minor: "24"
  platform: linux/amd64
kustomizeVersion: v4.5.4
serverVersion:
  buildDate: "2023-01-26T00:35:57Z"
  compiler: gc
  gitCommit: 546a94e9ae1c3be6f9c0dcde32a6e6672b035bc8
  gitTreeState: clean
  gitVersion: v1.24.10+k3s1
  goVersion: go1.19.5
  major: "1"
  minor: "24"
  platform: linux/amd64

@yockgen
Copy link
Author

yockgen commented Jul 11, 2024

Thanks! Unfortunately, the "installation script" way not work for me, see logs below:

root@cbl-yockgen [ /home/yockgen ]# curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.24.10+k3s1" sh -s - server --cluster-init --disable-selinux
[INFO]  Using v1.24.10+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.24.10+k3s1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.24.10+k3s1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
[INFO]  Finding available k3s-selinux versions
[ERROR]  Failed to find the k3s-selinux policy, please install:
    dnf install -y container-selinux
    dnf install -y https://rpm.rancher.io/k3s/stable/common/centos/9/noarch/

However, by added "INSTALL_K3S_SKIP_SELINUX_RPM=true", the installation script able to proceed:

curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="v1.30.2+k3s2" INSTALL_K3S_SKIP_SELINUX_RPM=true sh -s - server --cluster-init 

@zcobol
Copy link

zcobol commented Jul 11, 2024

@yockgen what version of Mariner are you using? The script won't execute install_selinux_rpm() unless it detects a redhat, centos, oracle, fedora or suse distro. See installation script beginning line 639:

install_selinux_rpm() {
    if [ -r /etc/redhat-release ] || [ -r /etc/centos-release ] || [ -r /etc/oracle-release ] || [ -r /etc/fedora-release ] || [ "${ID_LIKE%%[ ]*}" = "suse" ]; then
        repodir=/etc/yum.repos.d
        if [ -d /etc/zypp/repos.d ]; then
            repodir=/etc/zypp/repos.d
        fi
        set +o noglob
        $SUDO rm -f ${repodir}/rancher-k3s-common*.repo
        set -o noglob
        if [ -r /etc/redhat-release ] && [ "${3}" = "el7" ]; then
            $SUDO yum install -y yum-utils
            $SUDO yum-config-manager --enable rhel-7-server-extras-rpms
        fi
        $SUDO tee ${repodir}/rancher-k3s-common.repo >/dev/null << EOF
[rancher-k3s-common-${2}]
name=Rancher K3s Common (${2})
baseurl=https://${1}/k3s/${2}/common/${4}/noarch
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://${1}/public.key
EOF
        case ${3} in
        sle)
            rpm_installer="zypper --gpg-auto-import-keys"
            if [ "${TRANSACTIONAL_UPDATE=false}" != "true" ] && [ -x /usr/sbin/transactional-update ]; then
                transactional_update_run="transactional-update --no-selfupdate -d run"
                rpm_installer="transactional-update --no-selfupdate -d run ${rpm_installer}"
                : "${INSTALL_K3S_SKIP_START:=true}"
            fi
            # create the /var/lib/rpm-state in SLE systems to fix the prein selinux macro
            ${transactional_update_run} mkdir -p /var/lib/rpm-state
            ;;
        coreos)
            rpm_installer="rpm-ostree --idempotent"
            # rpm_install_extra_args="--apply-live"
            : "${INSTALL_K3S_SKIP_START:=true}"
            ;;
        *)
            rpm_installer="yum"
            ;;
        esac
        if [ "${rpm_installer}" = "yum" ] && [ -x /usr/bin/dnf ]; then
            rpm_installer=dnf
        fi
            if rpm -q --quiet k3s-selinux; then
            # remove k3s-selinux module before upgrade to allow container-selinux to upgrade safely
            if check_available_upgrades container-selinux ${3} && check_available_upgrades k3s-selinux ${3}; then
                MODULE_PRIORITY=$($SUDO semodule --list=full | grep k3s | cut -f1 -d" ")
                if [ -n "${MODULE_PRIORITY}" ]; then
                    $SUDO semodule -X $MODULE_PRIORITY -r k3s || true
                fi
            fi
        fi
        # shellcheck disable=SC2086
        $SUDO ${rpm_installer} install -y "k3s-selinux"
    fi
    return
}

Tested on Mariner2 and Mariner3 Beta the installer is not triggering this function, and you'll notice this in the logs [INFO] Skipping installation of SELinux RPM

@yockgen
Copy link
Author

yockgen commented Jul 12, 2024

My Mariner OS:

root@cbl-yockgen [ ~ ]# cat /etc/os-release
NAME="Common Base Linux Mariner"
VERSION="2.0.20240609"
ID=mariner
VERSION_ID="2.0"
PRETTY_NAME="CBL-Mariner/Linux"
ANSI_COLOR="1;34"
HOME_URL="https://aka.ms/cbl-mariner"
BUG_REPORT_URL="https://aka.ms/cbl-mariner"
SUPPORT_URL="https://aka.ms/cbl-mariner"
root@cbl-yockgen [ ~ ]# uname -r
5.15.158.2-1.cm2

Is it possible to added Mariner flag on line 639 to enabled it?

Thanks a lot of your advice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants