1.保证系统内核在最新版
#uname -r
2.关闭swap分区
#sed -ri ‘s/.swap./#&/’ /etc/fstab
3.关闭 selinux:
#sed -i ‘s/enforcing/disabled/’ /etc/selinux/config
4.调整k8s内核参数
cat > /etc/sysctl.d/kubernetes.conf << EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它
vm.overcommit_memory=1 # 不检查物理内存是否够用
vm.panic_on_oom=0 # 开启 OOM
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
EOF
5.安装docker源
#wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
6.配置镜像加速器
cat > /etc/docker/daemon.json <<EOF
{
“registry-mirrors”: [“https://ct8asqlq.mirror.aliyuncs.com”,
“https://docker.mirrors.ustc.edu.cn”],
},
“exec-opts”:[“native.cgroupdriver=systemd”]
}
EOF
7.配置k8s源
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1
EOF
以上是准备环境
8.docker和k8s一起安装,避免docker版本过高,引起安装失败
#yum -y install kubelet kubeadm kubectl docker
9.启动k8s和docker
#systemctl enable docker && systemctl start docker && systemctl status docker && systemctl enable kubelet && systemctl start kubelet && systemctl status kubelet
常用命令集
Kubectl get 显示资源列表
#kubectl get deployments #获取deployment的资源列表
#kubectl get pods #获取pod的资源列表
#kubectl get node #获取node的资源列表
在命令后加 -A 或者 --all_namespaces #查看所有名称空间的对象 -n查看指定名称空间的对象
#kubectl get node -A #查看所有节点的详细情况
#kubectl get deployment -n kube-system #查看deployment 的 kube-system的详情
kubectl describe - 显示有关资源的详细信息
#kubectl describe 资源类型 资源名称
#查看名称为nginx的Deployment的信息
kubectl describe deployment nginx
kubectl logs - 查看pod中的容器的打印日志
#kubectl logs nginx