192.168.129.160 k8s1
192.168.129.162 k8s2
192.168.129.164 k8s3
192.168.129.165 k8s4
192.168.129.166 k8s5
每一台虚拟机都是centos 7.4系统,4G内存,2个CPU,60或80G硬盘,校园网8M宽带,还是不稳定的那种,不想连外网,所以用了好多源
主要安装教程是:
非常感谢好心博主们的分享!!!
systemctl stop firewalld && systemctl disable firewalld
docker info | grep Cgroup
查看日志
journalctl -xefu kubelet
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk'/dashboard-admin/{print $1}')
kubectl create -f manifests/setup && \ until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done && \ kubectl create -f manifests/
kubectl get pod --all-namespaces
kubectl replace --force -f kube-state-metrics-rbac.yaml
kubectl replace --force -f kube-state-metrics-deployment.yaml
kubectl replace --force -f kube-state-metrics-service.yaml
用journalctl查看日志非常管用
journalctl -u kube-scheduler
journalctl -xefu kubelet
journalctl -u kube-apiserver
journalctl -u kubelet |tail
journalctl -xe
看系统日志
cat /var/log/messages
kubectl describe pod kubernetes-dashboard-849cd79b75-s2snt --namespace kube-system
kubectl logs -f pods/monitoring-influxdb-fc8f8d5cd-dbs7d -n kube-system
kubectl logs --tail 200 -f kube-apiserver -n kube-system |more
kubectl logs --tail 200 -f podname -n jenkins
用docker查看日志
docker logs c36c56e4cfa3
(容器id)
journalctl -u kubelet -f
查看集群日志
kubectl replace --force -f prometheus-configmap.yaml
关闭swap https://www.jianshu.com/p/6dae5c2c4dab
cat >> /etc/hosts << EOF
192.168.129.160 k8s1
192.168.129.162 k8s2
192.168.129.164 k8s3
192.168.129.165 k8s4
192.168.129.166 k8s5
EOF
安装docker后一定要进行:
修改或创建/etc/docker/daemon.json,加入下述内容:
{
“exec-opts”: [“native.cgroupdriver=systemd”]
}
重启docker:systemctl restart docker
不然后面K8S初始化会"warming" cgroup的问题:[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
出错后若要重新初始化K8S,使用kubeadm命令,执行:kubeadm reset
重新执行初始化:kubeadm init 。。。。
部署Kubernetes Master”时发生警告,“
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 18.03.0-ce. Latest validated version: 18.09
”原来安装的docker版本太低,要更新,参考:https://zhuanlan.zhihu.com/p/28154147
6. CentOS修改主机名(hostname):需要修改两处:一处是/etc/sysconfig/network,另一处是/etc/hosts,只修改任一处会导致系统启动异常。
7. 在节点 安装kubeadm、kubelet:
有个warmming:
warning: /var/cache/yum/x86_64/7/kubernetes/packages/697ad1a31f01e90f44ad3f0c8fe06f32d7bdd3b227fcf705275d5ad241d52eb6-kubeadm-1.16.0-0.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 3e1ba8d5: NOKEY
Public key for 697ad1a31f01e90f44ad3f0c8fe06f32d7bdd3b227fcf705275d5ad241d52eb6-kubeadm-1.16.0-0.x86_64.rpm is not installed
与这条命令有关
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
我是kubernetes-dashboard.yaml 有问题,
重新下载kubernetes-dashboard.yaml:https://codeload.github.com/liangbirui/dashboard/zip/v1.10.1
通过vim编辑yaml文件中默认的镜像源地址:这里替换为李振良老师的镜像地址。
containers:
- name: kubernetes-dashboard
#image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
image: lizhenliang/kubernetes-dashboard-amd64:v1.10.1
参考https://www.cnblogs.com/imstrive/p/11480424.html
error: unable to recognize "kubernetes-dashboard.yaml": no matches for kind "Deployment" in version "apps/v1beta2"
swapoff -a
$ 临时kubectl get pods,svc -n kube-system
查看k8s界面访问端口echo 'KUBELET_EXTRA_ARGS=--runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice' > /etc/sysconfig/kubelet
Failed to get system container stats for "/system.slice/docker.service": failed to get cgroup stats for "/system.slice/docker.service": failed to get container info for "/system.slice/docker.service": unknown container "/system.slice/docker.service"
sudo vim /etc/sysconfig/kubelet
--runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice
同时在vi /usr/lib/systemd/system/kubelet.service
里面修改: ExecStart=/usr/bin/kubelet --address=127.0.0.1 --pod-manifest-path=/etc/kubernetes/manifests --cgroup-driver=systemd --runtime-cgroups=/systemd/system.slice --kubelet-cgroups=/systemd/system.slice
然后重启K8S和docker
11. 安装cadvisor:
sudo docker run \ --volume=/:/rootfs:ro \
--volume=/var/run:/var/run:ro \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --volume=/dev/disk/:/dev/disk:ro \ --publish=8080:8080 \ --detach=true \ --name=cadvisor \ google/cadvisor:latest
Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of “crypto/rsa: verification error” while trying to verify candidate authority certificate “kubernetes”)
kubeadm reset
命令清除集群所有的配置rm -rf $HOME/.kube
命令删除这个目录kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.16.0 --apiserver-advertise-address 192.168.129.160 --pod-network-cidr=10.244.0.0/16 --token-ttl 0
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
node:
kubeadm reset
命令清除集群所有的配置
kubeadm join…
master:
kubectl apply -f kube-flannel.yml
kubectl get nodes
重启之后可以重新打开dashboard:
kubectl apply -f kubernetes-dashboard.yaml
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk’/dashboard-admin/{print $1}’)
访问https://192.168.129.160:30001并将上面命令得到的令牌输入
Warning FailedScheduling default-scheduler pod has unbound immediate PersistentVolumeClaims
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
kubectl describe pod prometheus-0 -n kube-system
得到下面信息:kubectl replace --force -f grafana.yaml
Warning! Detected 28802.76 seconds time difference between your browser and the server. Prometheus relies on accurate time and time drift might cause unexpected query results.
No datapoints found.
国内百度查出资料提示,系统时间有误;各种尝试换时间、时区,还是没有解决该问题。使用google查询该问题,发现是没有运行相对应的export, 或没有使用Prometheus集成export,数据没有采集到。- job_name: 'node'
static_configs:
- targets:
- 192.168.129.160:9100
- 192.168.129.162:9100
- 192.168.129.164:9100
kubectl replace --force -f prometheus-configmap.yaml
kubectl replace --force -f prometheus-statefulset.yaml
kubectl replace --force -f prometheus-service.yaml
等几分钟就好了
[root@node2 ~]# kubectl describe pod coredns-6c65fc5cbb-8ntpv
Error from server (NotFound): pods "coredns-6c65fc5cbb-8ntpv" not found