/*
k8s部署参考:
https://www.hangge.com/blog/cache/detail_2414.html
https://latelee.blog.csdn.net/article/details/103774072
kubeadm init --kubernetes-version=v1.21.2 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12
出现的问题:
1.The connection to the server localhost:8080 was refused - did you specify the right host or port?
解决方法:
master :
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
node节点:
cp master节点$HOME/.kube/config文件到node节点$HOME/.kube/config
2.flannel文件地址:
https://github.com/flannel-io/flannel/blob/master/Documentation/kube-flannel.yml
https://github.com/lei-all/flannel.yaml/blob/master/kube-flannel.yml
3.coedns出现system:coredns 无法list endpointslices,将endpointslices权限加上即可
*/
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:coredns
rules:
- apiGroups:
- ""
resources:
- endpoints
- services
- pods
- namespaces
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- apiGroups:
- "discovery.k8s.io"
resources:
- endpointslices
verbs:
- list
- get
- watch
4.配置tab自动补全:
1.安装bash-completion
[root@master bin]# yum install bash-completion -y
2.执行bash_completion
[root@master bin]# source /usr/share/bash-completion/bash_completion
3.重新加载kubectl completion
[root@master bin]# source <(kubectl completion bash)
4.就能用tab补全命令了
[root@master bin]# kubectl create clusterrolebinding
没安装bash-completion就会报错
source <(kubectl completion bash)
运行kubectl tab时出现以下报错
[root@master bin]# kubectl c-bash: _get_comp_words_by_ref: command not found
5.kubeadm reset
ifconfig cni0 down
ip link delete cni0
ifconfig flannel.1 down
ip link delete flannel.1
rm /var/lib/cni/ -rf
rm /etc/kubernetes/ -rf
rm /var/lib/kubelet/ -rf
rm $HOME/.kube/config -rf
token get:
https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-token/
kubeadm token create --print-join-command
#kubeadm config images list
images=(
kube-apiserver:v1.21.2
kube-controller-manager:v1.21.2
kube-scheduler:v1.21.2
kube-proxy:v1.21.2
pause:3.4.1
etcd:3.4.13-0
coredns/coredns:1.8.0
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.0 coredns/coredns:v1.8.0
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config