【云原生学习】Kubernetes集群上搭建KubeSphere 教程

文章目录

  • Kubernetes集群上搭建KubeSphere 教程
    • 描述
    • 环境准备
      • 移除docker相关包
      • 卸载podman
      • 卸载k8s
      • 安装Docker
      • 安装Kubernetes
        • 基本环境
        • 安装kubelet、kubeadm、kubectl
        • 使用kubeadm引导集群
          • 下载各个机器需要的镜像
        • 初始化master节点
        • 记录关键信息
        • 安装Calico网络插件
        • 加入worker节点
    • 安装KubeSphere前置环境
      • 安装nfs-server
      • 配置nfs-client(选做)
      • 配置默认存储
      • metrics-server
      • 安装KubeSphere
        • 下载核心文件
        • 修改cluster-configuration
        • 查看安装进度
        • 解决etcd监控证书找不到问题
  • K8S 问题“The connection to the server....:6443 was refused - did you specify the right host or port?

Kubernetes集群上搭建KubeSphere 教程

描述

KubeSphere®️ 是基于 Kubernetes 构建的分布式、多租户、多集群、企业级开源容器平台,具有强大且完善的网络与存储能力,并通过极简的人机交互提供完善的多集群管理、CI / CD 、微服务治理、应用管理等功能,帮助企业在云、虚拟化及物理机等异构基础设施上快速构建、部署及运维容器架构,实现应用的敏捷开发与全生命周期管理。

官网: https://kubesphere.qingcloud.com/、

Kubernetes安装教程:https://kubesphere.com.cn/docs/quick-start/minimal-kubesphere-on-k8s/

环境准备

准备三台服务器,搭建一主多从集群,配置如下:centos系统

服务器 节点 主机ip 配置
阿里云 master 8.134.124.163 :172.24.80.197 4核8G
阿里云 Node1 8.134.120.17: 172.24.80.1 8核16G
阿里云 Node2 8.134.114.33 : 172.24.80.196 8核16G

移除docker相关包

yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine

卸载podman

yum erase podman buildah

卸载k8s

yum remove -y kubelet kubeadm kubectl
kubeadm reset -f
modprobe -r ipip
lsmod
rm -rf ~/.kube/
rm -rf /etc/kubernetes/
rm -rf /etc/systemd/system/kubelet.service.d
rm -rf /etc/systemd/system/kubelet.service
rm -rf /usr/bin/kube*
rm -rf /etc/cni
rm -rf /opt/cni
rm -rf /var/lib/etcd
rm -rf /var/etcd

安装Docker

sudo yum remove docker*
sudo yum install -y yum-utils

#配置docker的yum地址
sudo yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo


#安装指定版本
sudo yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7 containerd.io-1.4.6

#	启动&开机启动docker
systemctl enable docker --now

# docker加速配置
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
 "registry-mirrors": ["https://82m9ar63.mirror.aliyuncs.com"],
 "exec-opts": ["native.cgroupdriver=systemd"],
 "log-driver": "json-file",
 "log-opts": {
   "max-size": "100m"
 },
 "storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

在三台服务器中都安装一下,安装成功后,使用docker 命令检查是否安装成功。

docker ps
docker image
docker info

安装Kubernetes

基本环境

先保证三台机子的私网ip能互相ping通:

ip a //查看当前服务器的私网ip
ping ip //互ping

配置每台机器的hostname:

hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2

当前命令,在三台机子都执行一遍。

# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

# 关闭防火墙
systemctl disable firewalld
systemctl stop firewalld

#关闭swap
swapoff -a  
sed -ri 's/.*swap.*/#&/' /etc/fstab

#允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

安装kubelet、kubeadm、kubectl

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
  http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF


sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes

sudo systemctl enable --now kubelet

在三台服务器上都执行一下安装命令,要注意的是 echo “192.168.159.130 k8s-master” >> /etc/hosts 这里改成自己master主机的私网ip请注意。

使用kubeadm引导集群

下载各个机器需要的镜像
sudo tee ./images.sh <<-'EOF'
#!/bin/bash
images=(
kube-apiserver:v1.20.9
kube-proxy:v1.20.9
kube-controller-manager:v1.20.9
kube-scheduler:v1.20.9
coredns:1.7.0
etcd:3.4.13-0
pause:3.2
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/$imageName
done
EOF
  
chmod +x ./images.sh && ./images.sh

初始化master节点

在master机器上执行初始化命令:

#所有机器添加master域名映射,以下需要修改为自己的
echo "192.168.211.115  cluster-endpoint" >> /etc/hosts

kubeadm init \
--apiserver-advertise-address=192.168.227.234 \
--control-plane-endpoint=cluster-endpoint \
--image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \
--kubernetes-version v1.20.9 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=173.168.0.0/16
   
   
   
  

这里的 apiserver-advertise-address ip修改为master主机ip: control-plane-endpoint如果上一步有改,也一起改。

记录关键信息

如果,初始化成功后,请保存控制台中的信息:

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

 mkdir -p $HOME/.kube
 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

 export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
 https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:

 kubeadm join k8s-master:6443 --token kwfdwx.m1bxp5q5o5qctcmh \
   --discovery-token-ca-cert-hash sha256:bf1d6cc1592e4b71e59d3a242513386a1d58683f67bc8adcceb61f2013ee144b \
   --control-plane 

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join k8s-master:6443 --token kwfdwx.m1bxp5q5o5qctcmh \
   --discovery-token-ca-cert-hash sha256:bf1d6cc1592e4b71e59d3a242513386a1d58683f67bc8adcceb61f2013ee144b 

执行返回的关键信息的命令:

mkdir -p $HOME/.kube
 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 sudo chown $(id -u):$(id -g) $HOME/.kube/config

安装Calico网络插件

curl https://docs.projectcalico.org/manifests/calico.yaml -O

kubectl apply -f calico.yaml

加入worker节点

这时候,在node节点上执行返回关键信息中的最后一段:节点加入,与主节点通信。

kubeadm join k8s-master:6443 --token kwfdwx.m1bxp5q5o5qctcmh \
   --discovery-token-ca-cert-hash sha256:bf1d6cc1592e4b71e59d3a242513386a1d58683f67bc8adcceb61f2013ee144b 

可以在主节点中查看:

kubectl get nodes

安装KubeSphere前置环境

安装nfs-server

每台机器执行下载。

yum install -y nfs-utils

在主机器中执行命令。以下命令,是把master 作为 nfs的服务器。

# 在master 执行以下命令 
echo "/nfs/data/ *(insecure,rw,sync,no_root_squash)" > /etc/exports


# 执行以下命令,启动 nfs 服务;创建共享目录
mkdir -p /nfs/data


# 在master执行
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server

# 使配置生效
exportfs -r

#检查配置是否生效
exportfs

配置nfs-client(选做)

在node节点中,执行命令,注意ip是自己master节点的ip。

showmount -e 192.168.63.158

mkdir -p /nfs/data

mount -t nfs 192.168.159.136:/nfs/data /nfs/data

配置默认存储

在master节点中创建一个sc.yaml文件:

## 创建了一个存储类
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
 name: nfs-storage
 annotations:
   storageclass.kubernetes.io/is-default-class: "true"
provisioner: k8s-sigs.io/nfs-subdir-external-provisioner
parameters:
 archiveOnDelete: "true"  ## 删除pv的时候,pv的内容是否要备份

---
apiVersion: apps/v1
kind: Deployment
metadata:
 name: nfs-client-provisioner
 labels:
   app: nfs-client-provisioner
 # replace with namespace where provisioner is deployed
 namespace: default
spec:
 replicas: 1
 strategy:
   type: Recreate
 selector:
   matchLabels:
     app: nfs-client-provisioner
 template:
   metadata:
     labels:
       app: nfs-client-provisioner
   spec:
     serviceAccountName: nfs-client-provisioner
     containers:
       - name: nfs-client-provisioner
         image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/nfs-subdir-external-provisioner:v4.0.2
         # resources:
         #    limits:
         #      cpu: 10m
         #    requests:
         #      cpu: 10m
         volumeMounts:
           - name: nfs-client-root
             mountPath: /persistentvolumes
         env:
           - name: PROVISIONER_NAME
             value: k8s-sigs.io/nfs-subdir-external-provisioner
           - name: NFS_SERVER
             value: 192.168.159.130 ## 指定自己nfs服务器地址
           - name: NFS_PATH  
             value: /nfs/data  ## nfs服务器共享的目录
     volumes:
       - name: nfs-client-root
         nfs:
           server: 192.168.159.130
           path: /nfs/data
---
apiVersion: v1
kind: ServiceAccount
metadata:
 name: nfs-client-provisioner
 # replace with namespace where provisioner is deployed
 namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
 name: nfs-client-provisioner-runner
rules:
 - apiGroups: [""]
   resources: ["nodes"]
   verbs: ["get", "list", "watch"]
 - apiGroups: [""]
   resources: ["persistentvolumes"]
   verbs: ["get", "list", "watch", "create", "delete"]
 - apiGroups: [""]
   resources: ["persistentvolumeclaims"]
   verbs: ["get", "list", "watch", "update"]
 - apiGroups: ["storage.k8s.io"]
   resources: ["storageclasses"]
   verbs: ["get", "list", "watch"]
 - apiGroups: [""]
   resources: ["events"]
   verbs: ["create", "update", "patch"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
 name: run-nfs-client-provisioner
subjects:
 - kind: ServiceAccount
   name: nfs-client-provisioner
   # replace with namespace where provisioner is deployed
   namespace: default
roleRef:
 kind: ClusterRole
 name: nfs-client-provisioner-runner
 apiGroup: rbac.authorization.k8s.io
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
 name: leader-locking-nfs-client-provisioner
 # replace with namespace where provisioner is deployed
 namespace: default
rules:
 - apiGroups: [""]
   resources: ["endpoints"]
   verbs: ["get", "list", "watch", "create", "update", "patch"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
 name: leader-locking-nfs-client-provisioner
 # replace with namespace where provisioner is deployed
 namespace: default
subjects:
 - kind: ServiceAccount
   name: nfs-client-provisioner
   # replace with namespace where provisioner is deployed
   namespace: default
roleRef:
 kind: Role
 name: leader-locking-nfs-client-provisioner
 apiGroup: rbac.authorization.k8s.io

把上面命令,复制进去,然后注意到是,里面有2处ip的设置,请设置自己的master服务器ip地址,然后保存。

kubectl apply -f sc.yaml

执行成功后,执行命令查看:

kubectl get sc

创建pv存储空间:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
 name: nginx-pvc
spec:
 accessModes:
   - ReadWriteMany
 resources:
   requests:
     storage: 200Mi

创建一个pvc.yaml文件把我上面的复制进去然后执行:

kubectl apply -f pvc.yaml

查看:

kubectl get pv
kubectl get pvc

metrics-server

集群指标监控信息:

apiVersion: v1
kind: ServiceAccount
metadata:
 labels:
   k8s-app: metrics-server
 name: metrics-server
 namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
 labels:
   k8s-app: metrics-server
   rbac.authorization.k8s.io/aggregate-to-admin: "true"
   rbac.authorization.k8s.io/aggregate-to-edit: "true"
   rbac.authorization.k8s.io/aggregate-to-view: "true"
 name: system:aggregated-metrics-reader
rules:
- apiGroups:
 - metrics.k8s.io
 resources:
 - pods
 - nodes
 verbs:
 - get
 - list
 - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
 labels:
   k8s-app: metrics-server
 name: system:metrics-server
rules:
- apiGroups:
 - ""
 resources:
 - pods
 - nodes
 - nodes/stats
 - namespaces
 - configmaps
 verbs:
 - get
 - list
 - watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
 labels:
   k8s-app: metrics-server
 name: metrics-server-auth-reader
 namespace: kube-system
roleRef:
 apiGroup: rbac.authorization.k8s.io
 kind: Role
 name: extension-apiserver-authentication-reader
subjects:
- kind: ServiceAccount
 name: metrics-server
 namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
 labels:
   k8s-app: metrics-server
 name: metrics-server:system:auth-delegator
roleRef:
 apiGroup: rbac.authorization.k8s.io
 kind: ClusterRole
 name: system:auth-delegator
subjects:
- kind: ServiceAccount
 name: metrics-server
 namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
 labels:
   k8s-app: metrics-server
 name: system:metrics-server
roleRef:
 apiGroup: rbac.authorization.k8s.io
 kind: ClusterRole
 name: system:metrics-server
subjects:
- kind: ServiceAccount
 name: metrics-server
 namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
 labels:
   k8s-app: metrics-server
 name: metrics-server
 namespace: kube-system
spec:
 ports:
 - name: https
   port: 443
   protocol: TCP
   targetPort: https
 selector:
   k8s-app: metrics-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
 labels:
   k8s-app: metrics-server
 name: metrics-server
 namespace: kube-system
spec:
 selector:
   matchLabels:
     k8s-app: metrics-server
 strategy:
   rollingUpdate:
     maxUnavailable: 0
 template:
   metadata:
     labels:
       k8s-app: metrics-server
   spec:
     containers:
     - args:
       - --cert-dir=/tmp
       - --kubelet-insecure-tls
       - --secure-port=4443
       - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
       - --kubelet-use-node-status-port
       image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/metrics-server:v0.4.3
       imagePullPolicy: IfNotPresent
       livenessProbe:
         failureThreshold: 3
         httpGet:
           path: /livez
           port: https
           scheme: HTTPS
         periodSeconds: 10
       name: metrics-server
       ports:
       - containerPort: 4443
         name: https
         protocol: TCP
       readinessProbe:
         failureThreshold: 3
         httpGet:
           path: /readyz
           port: https
           scheme: HTTPS
         periodSeconds: 10
       securityContext:
         readOnlyRootFilesystem: true
         runAsNonRoot: true
         runAsUser: 1000
       volumeMounts:
       - mountPath: /tmp
         name: tmp-dir
     nodeSelector:
       kubernetes.io/os: linux
     priorityClassName: system-cluster-critical
     serviceAccountName: metrics-server
     volumes:
     - emptyDir: {}
       name: tmp-dir
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
 labels:
   k8s-app: metrics-server
 name: v1beta1.metrics.k8s.io
spec:
 group: metrics.k8s.io
 groupPriorityMinimum: 100
 insecureSkipTLSVerify: true
 service:
   name: metrics-server
   namespace: kube-system
 version: v1beta1
 versionPriority: 100

创建一个metrics.yaml文件,把上面的复制进去:

kubectl apply -f metrics.yaml

执行成功后可以查看:

kubectl  get pod -A

安装KubeSphere

下载核心文件

wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/kubesphere-installer.yaml

wget https://github.com/kubesphere/ks-installer/releases/download/v3.1.1/cluster-configuration.yaml

如果网络卡,可以在github下。去下载当前文件。

修改cluster-configuration

我这里就执行把我修改好的文件,复制在下面,你们直接创建一个cluster-configuration.yaml 复制进去就行。

---
apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:
 name: ks-installer
 namespace: kubesphere-system
 labels:
   version: v3.1.1
spec:
 persistence:
   storageClass: ""        # If there is no default StorageClass in your cluster, you need to specify an existing StorageClass here.
 authentication:
   jwtSecret: ""           # Keep the jwtSecret consistent with the Host Cluster. Retrieve the jwtSecret by executing "kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v "apiVersion" | grep jwtSecret" on the Host Cluster.
 local_registry: ""        # Add your private registry address if it is needed.
 etcd:
   monitoring: true       # Enable or disable etcd monitoring dashboard installation. You have to create a Secret for etcd before you enable it.
   endpointIps: 192.168.159.136  # etcd cluster EndpointIps. It can be a bunch of IPs here.
   port: 2379              # etcd port.
   tlsEnable: true
 common:
   redis:
     enabled: true
   openldap:
     enabled: true
   minioVolumeSize: 20Gi # Minio PVC size.
   openldapVolumeSize: 2Gi   # openldap PVC size.
   redisVolumSize: 2Gi # Redis PVC size.
   monitoring:
     # type: external   # Whether to specify the external prometheus stack, and need to modify the endpoint at the next line.
     endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090 # Prometheus endpoint to get metrics data.
   es:   # Storage backend for logging, events and auditing.
     # elasticsearchMasterReplicas: 1   # The total number of master nodes. Even numbers are not allowed.
     # elasticsearchDataReplicas: 1     # The total number of data nodes.
     elasticsearchMasterVolumeSize: 4Gi   # The volume size of Elasticsearch master nodes.
     elasticsearchDataVolumeSize: 20Gi    # The volume size of Elasticsearch data nodes.
     logMaxAge: 7                     # Log retention time in built-in Elasticsearch. It is 7 days by default.
     elkPrefix: logstash              # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log.
     basicAuth:
       enabled: false
       username: ""
       password: ""
     externalElasticsearchUrl: ""
     externalElasticsearchPort: ""
 console:
   enableMultiLogin: true  # Enable or disable simultaneous logins. It allows different users to log in with the same account at the same time.
   port: 30880
 alerting:                # (CPU: 0.1 Core, Memory: 100 MiB) It enables users to customize alerting policies to send messages to receivers in time with different time intervals and alerting levels to choose from.
   enabled: true         # Enable or disable the KubeSphere Alerting System.
   # thanosruler:
   #   replicas: 1
   #   resources: {}
 auditing:                # Provide a security-relevant chronological set of records,recording the sequence of activities happening on the platform, initiated by different tenants.
   enabled: true         # Enable or disable the KubeSphere Auditing Log System. 
 devops:                  # (CPU: 0.47 Core, Memory: 8.6 G) Provide an out-of-the-box CI/CD system based on Jenkins, and automated workflow tools including Source-to-Image & Binary-to-Image.
   enabled: true             # Enable or disable the KubeSphere DevOps System.
   jenkinsMemoryLim: 2Gi      # Jenkins memory limit.
   jenkinsMemoryReq: 1500Mi   # Jenkins memory request.
   jenkinsVolumeSize: 8Gi     # Jenkins volume size.
   jenkinsJavaOpts_Xms: 512m  # The following three fields are JVM parameters.
   jenkinsJavaOpts_Xmx: 512m
   jenkinsJavaOpts_MaxRAM: 2g
 events:                  # Provide a graphical web console for Kubernetes Events exporting, filtering and alerting in multi-tenant Kubernetes clusters.
   enabled: true         # Enable or disable the KubeSphere Events System.
   ruler:
     enabled: true
     replicas: 2
 logging:                 # (CPU: 57 m, Memory: 2.76 G) Flexible logging functions are provided for log query, collection and management in a unified console. Additional log collectors can be added, such as Elasticsearch, Kafka and Fluentd.
   enabled: true         # Enable or disable the KubeSphere Logging System.
   logsidecar:
     enabled: true
     replicas: 2
 metrics_server:                    # (CPU: 56 m, Memory: 44.35 MiB) It enables HPA (Horizontal Pod Autoscaler).
   enabled: false                   # Enable or disable metrics-server.
 monitoring:
   storageClass: ""                 # If there is an independent StorageClass you need for Prometheus, you can specify it here. The default StorageClass is used by default.
   # prometheusReplicas: 1          # Prometheus replicas are responsible for monitoring different segments of data source and providing high availability.
   prometheusMemoryRequest: 400Mi   # Prometheus request memory.
   prometheusVolumeSize: 20Gi       # Prometheus PVC size.
   # alertmanagerReplicas: 1          # AlertManager Replicas.
 multicluster:
   clusterRole: none  # host | member | none  # You can install a solo cluster, or specify it as the Host or Member Cluster.
 network:
   networkpolicy: # Network policies allow network isolation within the same cluster, which means firewalls can be set up between certain instances (Pods).
     # Make sure that the CNI network plugin used by the cluster supports NetworkPolicy. There are a number of CNI network plugins that support NetworkPolicy, including Calico, Cilium, Kube-router, Romana and Weave Net.
     enabled: true # Enable or disable network policies.
   ippool: # Use Pod IP Pools to manage the Pod network address space. Pods to be created can be assigned IP addresses from a Pod IP Pool.
     type: calico # Specify "calico" for this field if Calico is used as your CNI plugin. "none" means that Pod IP Pools are disabled.
   topology: # Use Service Topology to view Service-to-Service communication based on Weave Scope.
     type: none # Specify "weave-scope" for this field to enable Service Topology. "none" means that Service Topology is disabled.
 openpitrix: # An App Store that is accessible to all platform tenants. You can use it to manage apps across their entire lifecycle.
   store:
     enabled: true # Enable or disable the KubeSphere App Store.
 servicemesh:         # (0.3 Core, 300 MiB) Provide fine-grained traffic management, observability and tracing, and visualized traffic topology.
   enabled: true     # Base component (pilot). Enable or disable KubeSphere Service Mesh (Istio-based).
 kubeedge:          # Add edge nodes to your cluster and deploy workloads on edge nodes.
   enabled: true   # Enable or disable KubeEdge.
   cloudCore:
     nodeSelector: {"node-role.kubernetes.io/worker": ""}
     tolerations: []
     cloudhubPort: "10000"
     cloudhubQuicPort: "10001"
     cloudhubHttpsPort: "10002"
     cloudstreamPort: "10003"
     tunnelPort: "10004"
     cloudHub:
       advertiseAddress: # At least a public IP address or an IP address which can be accessed by edge nodes must be provided.
         - ""            # Note that once KubeEdge is enabled, CloudCore will malfunction if the address is not provided.
       nodeLimit: "100"
     service:
       cloudhubNodePort: "30000"
       cloudhubQuicNodePort: "30001"
       cloudhubHttpsNodePort: "30002"
       cloudstreamNodePort: "30003"
       tunnelNodePort: "30004"
   edgeWatcher:
     nodeSelector: {"node-role.kubernetes.io/worker": ""}
     tolerations: []
     edgeWatcherAgent:
       nodeSelector: {"node-role.kubernetes.io/worker": ""}
       tolerations: []

注意点是: endpointIps 这里改成自己主机器的ip。

然后在master服务器中执行命令:

kubectl apply -f kubesphere-installer.yaml
kubectl apply -f 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

访问任意机器的 30880端口

账号 : admin

密码 : P@88w0rd

解决etcd监控证书找不到问题

查看pod的时候会发现有一个监控的prometheus 下载不下来,执行一下命令就好了:

kubectl -n kubesphere-monitoring-system create secret generic kube-etcd-client-certs  --from-file=etcd-client-ca.crt=/etc/kubernetes/pki/etcd/ca.crt  --from-file=etcd-client.crt=/etc/kubernetes/pki/apiserver-etcd-client.crt  --from-file=etcd-client.key=/etc/kubernetes/pki/apiserver-etcd-client.key

然后,在进行登录就安装成功了。

【云原生学习】Kubernetes集群上搭建KubeSphere 教程_第1张图片

K8S 问题“The connection to the server…:6443 was refused - did you specify the right host or port?

问题“The connection to the server…:6443 was refused - did you specify the right host or port?”的处理!
问题“The connection to the server :6443 was refused - did you specify the right host or port?”的处理!

一、故障产生

在不关闭kubernets相关服务的情况下,对kubernets的master节点进行重启。(模拟服务器的异常掉电)

二、故障状况

启动后无法远程到kubernets的dashbaord,后进行如下命令报错。

kubectl get nodes
#The connection to the server <master>:6443 was refused - did you specify the right host or port?

故障处理:

1.检查环境变量情况(正常)

env | grep -i kub

2.检查docker服务(正常)

systemctl status docker.service

3.检查kubelet服务(表面正常)

systemctl status kubelet.service

4.查看端口是是否被监听(没有监听)

netstat -pnlt | grep 6443

5.检查防火墙状态(正常)

systemctl status firewalld.service

6.查看日志

journalctl -xeu kubelet

6.1 重新导入一下API镜像即可。

docker load -i kube-apiserver-amd64_v1.9.0.tar

6.2 重启docker和kubelet服务

systemctl restart docker.service

systemctl restart kubelet.service

6.3 检查服务(此时正常)

kubectl get nodes

you specify the right host or port?”的处理!

一、故障产生

在不关闭kubernets相关服务的情况下,对kubernets的master节点进行重启。(模拟服务器的异常掉电)

二、故障状况

启动后无法远程到kubernets的dashbaord,后进行如下命令报错。

kubectl get nodes
#The connection to the server <master>:6443 was refused - did you specify the right host or port?

故障处理:

1.检查环境变量情况(正常)

env | grep -i kub

2.检查docker服务(正常)

systemctl status docker.service

3.检查kubelet服务(表面正常)

systemctl status kubelet.service

4.查看端口是是否被监听(没有监听)

netstat -pnlt | grep 6443

5.检查防火墙状态(正常)

systemctl status firewalld.service

6.查看日志

journalctl -xeu kubelet

6.1 重新导入一下API镜像即可。

docker load -i kube-apiserver-amd64_v1.9.0.tar

6.2 重启docker和kubelet服务

systemctl restart docker.service

systemctl restart kubelet.service

6.3 检查服务(此时正常)

kubectl get nodes

你可能感兴趣的:(云原生,云原生)