1小时上手k8s版vue:kubesphere

182 阅读2分钟

一键搭建kubesphere3.4环境(ALL in One 模式)

官方文档

环境准备

apt-get update
yum install conntrack socat -y

安装kk并授权

# 国内配置
export KKZONE=cn

# 安装kk工具
curl -sfL https://get-kk.kubesphere.io | VERSION=v3.0.13 sh -

# 授权kk
chmod +x kk

# 设定主机名
hostnamectl set-hostname kubesphere
# 安装kub
export KKZONE=cn
安装kubesphere
./kk create cluster --with-kubernetes v1.22.12 --with-kubesphere v3.4.0

安装成功后,会打印默认用户名密码

#####################################################

###              Welcome to KubeSphere!           ###

#####################################################



Console: http://192.168.0.2:30880

Account: admin

Password: P@88w0rd

NOTES:

  1. After you log into the console, please check the
     monitoring status of service components in
     "Cluster Management". If any service is not
     ready, please wait patiently until all components 
     are up and running.
  2. Please change the default password after login.

#####################################################

https://kubesphere.io             20xx-xx-xx xx:xx:xx

#####################################################

image.png

kubesphere快速使用

创建企业空间&项目

点击 平台管理->访问控制-创建

创建保密字典(docker仓库,以阿里镜像仓库为例)

image.png 点击验证,镜像验证通过后,点击创建 image.png

创建自制应用

  • 选择自制应用 image.png

  • 输入应用名 image.png

  • 如果是前后后端项目则选择无状态服务,如果是mysql、redis则选择有状态服务 image.png

  • 容器组设置-基本信息 image.png

  • 容器组设置-选择镜像及版本 image.png

  • 容器组设置-使用镜像默认端口号 image.png

  • 容器组设置-点击同步主机时区 image.png

  • 容器组设置-存储设置,使用默认设置

image.png

  • 容器组设置-高级设置 勾选外部访问并选择访问模式为NodePort,这样就可以使用ip+NodePort端口访问服务。

创建应用路由,通过ingress方式访问

路由配置

image.png

  • http访问,配置域名及转发规则,并选择现有服务和端口 image.png

  • https方式访问 首先在 配置-> 配置字典 中创建 TLS 字典,并配置 证书和私钥

配置允许80访问端口

vim /etc/kubernetes/manifests/kube-apiserver.yaml

在 command 下添加 - --service-node-port-range=1-65535 参数,编辑完成后会自动更新。此处参考文章

image.png

image.png

配置允许跨域

方式一,带年纪编辑注解进行配置

image.png

image.png

方式二,点击编辑Yaml并在annotations 下面添加下面配置

    nginx.ingress.kubernetes.io/cors-allow-headers: >-
      DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Accept,Referer,Access-Control-Request-Headers,Access-Control-Request-Method,Origin,Sec-Fetch-Mode,Token
    nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, OPTIONS'
    nginx.ingress.kubernetes.io/cors-allow-origin: '*'
    nginx.ingress.kubernetes.io/enable-cors: 'true'

完整配置

kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: wiki-app-ingress-0ii30f
  namespace: wiki
  labels:
    app.kubernetes.io/name: wiki-app
    app.kubernetes.io/version: v1
  annotations:
    kubesphere.io/creator: admin
    nginx.ingress.kubernetes.io/cors-allow-headers: >-
      DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Accept,Referer,Access-Control-Request-Headers,Access-Control-Request-Method,Origin,Sec-Fetch-Mode,Token
    nginx.ingress.kubernetes.io/cors-allow-methods: 'PUT, GET, POST, OPTIONS'
    nginx.ingress.kubernetes.io/cors-allow-origin: '*'
    nginx.ingress.kubernetes.io/enable-cors: 'true'
spec:
  tls:
    - hosts:
        - demo.zzcit.com
      secretName: demo-ssh-cert
  rules:
    - host: demo.zzcit.com
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: wiki-node-api
                port:
                  number: 8001
    - host: demo.zzcit.com
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: wiki-node-api
                port:
                  number: 8001