1)修改内核参数和模块
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#使内核参数配置生效
sysctl --system && modprobe br_netfilter && lsmod | grep br_netfilter
2)关闭交换内存
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
3)配置国内阿里云docker源,安装docker
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl start docker && systemctl enable docke
4)配置daemon.json,国内镜像加速,将容器数据默认更改为数据盘
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://registry.docker-cn.com",
"https://docker.mirrors.ustc.edu.cn",
"https://cr.console.aliyun.com",
"https://mirror.ccs.tencentyun.com"
],
"data-root": "/data/docker"
}
5)配置kubernetes yum源,用以安装Kubernetes基础服务及工具,此处使用阿里云镜像仓库源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
6)安装Kubernetes基础服务及工具
yum -y install kubelet-1.13* kubeadm-1.13* kubectl-1.13*
systemctl start kubelet
systemctl enable kubelet.service
7)下载k8s相关镜像并打标签
for i in `kubeadm config images list`; do
imageName=${i#k8s.gcr.io/}
docker pull registry.aliyuncs.com/google_containers/$imageName
docker tag registry.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
docker rmi registry.aliyuncs.com/google_containers/$imageName
done;
8)初始化k8s和网络
kubeadm init --apiserver-advertise-address=192.168.83.165 --kubernetes-version=v1.13.12 --pod-network-cidr=10.100.0.0/16 --ignore-preflight-errors=all
#安装成功标志
#Your Kubernetes master has initialized successfully!
#开机启动 && 启动服务
systemctl enable kubelet && systemctl start kubelet
9)初始化kubectl配置
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')
10)默认k8s的master节点是不能跑pod的业务,需要执行以下命令解除限制
kubectl taint nodes --all node-role.kubernetes.io/master-
#如果不允许调度
#kubectl taint nodes master1 node-role.kubernetes.io/master=:NoSchedule
#污点可选参数
NoSchedule: 一定不能被调度
PreferNoSchedule: 尽量不要调度
NoExecute: 不仅不会调度, 还会驱逐Node上已有的Pod
11)查看主节点运行 Pod 的状态
kubectl get pods --all-namespaces -o wide
12)测试创建一个nginx
# 创建一个nginx服务
kubectl create deployment nginx --image=nginx:1.14-alpine
#暴露端口
kubectl expose deploy nginx --port=80 --target-port=80 --type=NodePort
13)验证查看服务
kubectl get pod,svc
标签:kubectl,https,ku,kubernetes,--,安装,测试,docker,com
From: https://blog.51cto.com/Rain/6994289