kubectl 查看集群信息
2021-02-10 tech kubernetes 1 mins 1 图 269 字
一般情况下使用 kubectl cluster-info dump
命令可以找到
获取service IP段
kubectl cluster-info dump | grep service-cluster-ip-range
获取 pod IP段
kubectl cluster-info dump | grep -m 1 cluster-cidr
如下图所示:
一般情况下使用 kubectl cluster-info dump
命令可以找到
获取service IP段
kubectl cluster-info dump | grep service-cluster-ip-range
获取 pod IP段
kubectl cluster-info dump | grep -m 1 cluster-cidr
如下图所示:
grep -C n serch # 显示查找文件中匹配serch字串那行以及上下n行
grep -B n serch # 显示查找文件中匹配serch字串那行以及前n行 before
grep -A n serch # 显示查找文件中匹配serch字串那行以及后n行 after
sed -i "s/oldstring/newstring/g" `grep oldstring -rl yourdir`
例如:
sed -i "s/n1/kelu-n1/g" `ls`
kubesphere 是青云开源的 kubernetes 管理平台,可以纳管原生 的 Kubernetes。我个人挺喜欢他们的UI设计,从kubesphere 1.0 就关注了,当时无法在本地环境中安装,只能蹭了一波他们销售发放的优惠券在云上安装体验。近期又尝试在我本地纯净的kubernetes集群上安装 kubesphere 3.0,虽然仍然有一小番波折,不过总算是安装好了。这篇文章记录相关的要点。
我的 kubernetes 版本 v1.20.2,没有任何可用的外部存储,所能依靠的只有 local-storage。
节点可用资源:1c2g
安装默认storage class
创建 sc。
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
参考:存储类
配置为默认 sc
kubectl patch storageclass local-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
查看已经运行ok
kubectl get sc
跌跌撞撞一共起了6个 pv,如图:
分别用于redis、Prometheus、openldap,如果后期安装 service mesh(可选),还需要为 es 起 对应的pv。
以下的yaml文件注意修改亲和性相关的配置。
创建目录
mkdir -p /app/redis /app/prometheus1 /app/prometheus2 /app/openldap /app/es/data /app/es/data2
redis,10G
apiVersion: v1
kind: PersistentVolume
metadata:
name: redis-pv
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /app/redis
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- 10.184.0.131
Prometheus,20G
apiVersion: v1
kind: PersistentVolume
metadata:
name: prometheus-pv-1
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /app/prometheus1
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- 10.184.0.131
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: prometheus-pv-2
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /app/prometheus2
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- 10.184.0.131
openldap,10G
apiVersion: v1
kind: PersistentVolume
metadata:
name: prom2-pv
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /app/openldap
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- 10.184.0.133
service mesh/es,20G (可选)
apiVersion: v1
kind: PersistentVolume
metadata:
name: es-data-pv
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /app/es/data
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- 10.184.0.131
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: es-data2-pv
spec:
capacity:
storage: 20Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: local-storage
local:
path: /app/es/data2
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- 10.184.0.131
- 10.184.0.132
- 10.184.0.133
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/kubesphere-installer.yaml
kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.0.0/cluster-configuration.yaml
等待20分钟左右。
kubectl get po --all-namespaces
可以通过命令行查看安装过程。初始只有一个Pod ks-installer,它在Pod中运行ansible,可以查看它的日志,如果有错误就针对性地解决错误:
kubectl logs -f -n kubesphere-system ks-installer-xxx
安装完成后日志应该如下:
至此已经可以使用了。我尝试了开启 service mesh,有三个pod一直无法启动。因为只是随手玩玩,就不深究了。kubesphere的service mesh还是老版本的istio,就是还处于分离状态的组件,不是1.5版本之后的单体istio。
开启办法参考文档:https://kubesphere.io/docs/pluggable-components/service-mesh/
页面左上角 平台管理->集群管理->自定义资源crd-> 搜索 clusterconfiguration -> 进入
拉到最后,将 service mesh 配置 enabled 改为 true,即可。
查看安装进度:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
无法登录,account not active
查阅了不少 github issue,基本的情况是openldap那个容器相关的存储或者网络有问题。我一开始没有挂pv,估计是这个原因导致的问题。
实际上挂上pv之后仍然不行。最后重启kubesphere 所有的pod之后可以登陆了。
service mesh 仍然有3个pod无法启动。
因为只是顺手在做,并不使用,先记录一下,目前没去理。
参考使用kubesphere的卸载脚本即可:
https://github.com/kubesphere/ks-installer/blob/release-3.1/scripts/kubesphere-delete.sh
helm 是 k8s 的一个包管理工具,可以简化k8s应用的部署和管理,可以理解为yum和或者apt等包管理工具。
18年的时候记录过相关的笔记,当时是还是v2版本,v3 版本有了重大变化,当时的文章已经不合适了,故而重新记录helm相关的安装和使用笔记。
wget https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz
tar zxvf helm-v3.2.1-linux-amd64.tar.gz
mv ./linux-amd64/helm /usr/bin
helm repo add stable https://charts.helm.sh/stable
helm repo add incubator https://charts.helm.sh/incubator
helm repo update
早先使用的是这个源:
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
添加的时候一直报错:
Error: looks like "https://kubernetes-charts.storage.googleapis.com" is not a valid chart repository or cannot be reached: failed to fetch https://kubernetes-charts.storage.googleapis.com/index.yaml : 403 Forbidden
原来是2020.11.13 后改了这个地址了。
以安装kubefed为例:
添加源
$ helm repo add kubefed-charts https://raw.githubusercontent.com/kubernetes-sigs/kubefed/master/charts
$ helm repo update
搜索
$ helm search repo kubefed
NAME CHART VERSION APP VERSION DESCRIPTION
kubefed-charts/kubefed 0.6.1 KubeFed helm chart
安装
$ helm --namespace kube-federation-system upgrade -i kubefed kubefed-charts/kubefed --version=0.6.1 --create-namespace
Release "kubefed" does not exist. Installing it now.
NAME: kubefed
LAST DEPLOYED: Wed Aug 5 16:03:46 2020
NAMESPACE: kube-federation-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
下载到本地
helm pull kubefed-charts/kubefed