一、在 Kubernetes 上最小化安装 KubeSphere
除了在 Linux 机器上安装 KubeSphere 之外,您还可以将其直接部署在现有的 Kubernetes 集群上。本快速入门指南将引导您完成在 Kubernetes 上最小化安装 KubeSphere 的一般性步骤。
Prerequisites
- 如需在 Kubernetes 上安装 KubeSphere 3.2.1,您的 Kubernetes 版本必须为:1.19.x、1.20.x、1.21.x 或 1.22.x(实验性支持)。
- 确保您的机器满足最低硬件要求:CPU > 1 核,内存 > 2 GB。
- 在安装之前,需要配置 Kubernetes 集群中的默认存储类型。没有存储类型就会出现以下错误:
- 这里我安装的nfs
部署 KubeSphere
确保您的机器满足安装的前提条件之后,可以按照以下步骤安装 KubeSphere。
-
执行以下命令开始安装:
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.2.1/kubesphere-installer.yaml kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.2.1/cluster-configuration.yaml
-
检查安装日志:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
-
使用
kubectl get pod --all-namespaces
查看所有 Pod 是否在 KubeSphere 的相关命名空间中正常运行。如果是,请通过以下命令检查控制台的端口(默认为30880
):kubectl get svc/ks-console -n kubesphere-system
-
确保在安全组中打开了端口
30880
,并通过 NodePort(IP:30880)
使用默认帐户和密码(admin/P@88w0rd)
访问 Web 控制台。 -
登录控制台后,您可以在系统组件中检查不同组件的状态。如果要使用相关服务,可能需要等待某些组件启动并运行。
遇到的问题:
1.E0106 11:04:19.993753 1 reflector.go:131] pkg/mod/k8s.io/client-go@v0.0.0-20190411052641-7a6b4715b709/tools/cache/reflector.go:99: Failed to list *unstructured.Unstructured: Get "https://10.233.0.1:443/apis/installer.kubesphere.io/v1alpha1/namespaces/kubesphere-system/clusterconfigurations?fieldSelector=metadata.name%3Dks-installer&limit=500&resourceVersion=0": dial tcp 10.233.0.1:443: connect: no route to host
解决方法:
root@scarlettzhao-master:/home/scarlettzhao# systemctl stop kubelet
root@scarlettzhao-master:/home/scarlettzhao# iptables --flush
root@scarlettzhao-master:/home/scarlettzhao# iptables -tnat --flush
root@scarlettzhao-master:/home/scarlettzhao# systemctl start kubelet
root@scarlettzhao-master:/home/scarlettzhao# systemctl start docker
root@scarlettzhao-master:/home/scarlettzhao# kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
2.
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
Error from server: no preferred addresses found; known addresses: []
从 Kubernetes 上卸载 KubeSphere
您可以使用 kubesphere-delete.sh 将 KubeSphere 从您现有的 Kubernetes 集群中卸载。复制 GitHub 源文件并在本地机器上执行此脚本。
警告:
卸载意味着 KubeSphere 会从您的 Kubernetes 集群中移除。此操作不可逆并且没有任何备份,请谨慎操作。
二、在k8s上部署docker镜像
1. 创建 yaml 文件
pod yaml 模板
apiVersion: apps/v2
kind: Deployment
metadata:
labels:
app: ideali
name: ideali-deployment
name: ideali-pod
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: ideali
template:
metadata:
labels:
app: ideali
spec:
containers:
- image: registry.cn-shanghai.aliyuncs.com/via_scarlett/xx:v1.0 #你的镜像地址
imagePullPolicy: Always
name: ideali
ports:
- containerPort: 8080
name: ideali-port
volumes:
- hostPath:
path: /home/scarlett/ideali/logs
name: logs-volume
service yaml 模板
apiVersion: v1
kind: Service
metadata:
labels:
app: ideali
name: ideali-service
namespace: default
spec:
ports:
- name: ideali-port
nodePort: 30081
port: 8080
selector:
app: ideali
type: NodePort
2.找一台工作节点服务器,创建 **.yaml 文件。
root@ks-allinone:/home/scarlettzhao/ideali# ls
ideali_deployment.yaml ideali_service.yaml
kubectl create -f ideali_development.yaml
kubectl create -f ideali_service.yaml
查看部署状态
kubectl get pods
kubectl get svc
3.在kubersphere上查看部署状态
访问virtualIP:http://10.233.17.94/ 即可查看当前部署的服务