美文网首页K3S
五分钟单机离线安装k8s 1.20版本用于开发测试(k3s版)

五分钟单机离线安装k8s 1.20版本用于开发测试(k3s版)

作者: 万州客 | 来源:发表于2021-01-14 16:56 被阅读0次

    五分钟,看是噱头。其实文件下载到位的话,一分钟,也不是不可能。

    一,官网

    https://k3s.io/

    二,文档

    https://rancher.com/docs/k3s/latest/en/

    三,下载

    http://mirror.cnrancher.com/
    进入到k3s的v1.20.0-k3s2/目录下载k3s和k3s-airgap-images-amd64.tar文件。
    而k3s-install.sh在上一级目录。

    • k3s:k3s的可执行文件,kubectl别名

    • k3s-airgap-images-amd64.tar:离线安装镜像包

    • k3s-install.sh:安装脚本

    四,安装过程

    1,先安装依赖(如果需要)

    yum install -y container-selinux selinux-policy-base
    yum install -y https://rpm.rancher.io/k3s-selinux-0.1.1-rc1.el7.noarch.rpm

    2,将k3s拷贝到可执行目录

    以下步骤使用root帐号
    cp k3s /usr/local/bin/

    3,设置环境变量

    export INSTALL_K3S_SKIP_DOWNLOAD=true

    export INSTALL_K3S_EXEC="--docker --bind-address=1.2.3.4 \
        kube-apiserver-arg service-node-port-range=30000-50000 \
        --no-deploy traefik \
        --no-deploy servicelb \
        --no-deploy local-storage \
        --no-deploy metrics-server  \
        --write-kubeconfig ~/.kube/config \
        --write-kubeconfig-mode 666"
    
    • 本地已有镜像,无须下载
    • 使用docker服务,无须部署servicelb, traefik, local-storage, metrics-server
    • 可选禁用项:coredns, servicelb, traefik,local-storage, metrics-server

    4,运行安装脚本

    sh k3s-install.sh
    输出

    [INFO]  Skipping k3s download and verify
    [INFO]  Skipping installation of SELinux RPM
    [INFO]  Creating /usr/local/bin/kubectl symlink to k3s
    [INFO]  Skipping /usr/local/bin/crictl symlink to k3s, command exists in PATH at /usr/bin/crictl
    [INFO]  Skipping /usr/local/bin/ctr symlink to k3s, command exists in PATH at /usr/bin/ctr
    [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
    [INFO]  systemd: Starting k3s
    

    5,获取kubeconfig文件

    cat ~/.kube/config
    以下步骤使用普通帐号,将root下的kubeconfig文件内容,cp到普通帐号的对应目录即可。

    6,测试yaml

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
    spec:
      selector:
        matchLabels:
          app: nginx
      replicas: 1
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.18-alpine
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 80
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nginx-service
    spec:
      selector:
        app: nginx
      ports:
      - protocol: TCP
        name: http
        port: 80
        targetPort: 80
      type: NodePort
    
    

    相关文章

      网友评论

        本文标题:五分钟单机离线安装k8s 1.20版本用于开发测试(k3s版)

        本文链接:https://www.haomeiwen.com/subject/rlbvaktx.html