准备3台centos 7+ (建议7以上,不然要会很麻烦,要升级内核等等,扯淡的东西)
安装docker 和k8s集群(均以最新版为例)基于官网
设置静态ip(可选)
查看本机的网关ip
cd /Library/Preferences/VMware Fusion/vmnet8
cat nat.conf
进入centos7
改
service network restart
修改主机名(可选)
echo 'newhostname' > /etc/hostname
centos 7:(可选)
更改模式命令:systemctl set-default graphical.target由命令行模式更改为图形界面模式
systemctl set-default multi-user.target由图形界面模式更改为命令行模式
更改后验证是否正确 shutdown -r now
关闭防火墙(建议)
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
systemctl disable firewalld.service
systemctl stop firewalld.service
systemctl status firewalld.service
yum 安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli
systemctl enable docker
systemctl start docker
设置docker国内镜像仓库地址 阿里加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://wwpko457.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
禁用虚拟内存
sudo swapoff -a
设置k8s下载源
cat >> /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
yum install -y kubelet kubeadm kubectl
— 开机启动
systemctl enable kubelet
systemctl start kubelet
Eg:
docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.17.0
docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.17.0 k8s.gcr.io/kube-proxy:v1.17.0
docker pull registry.aliyuncs.com/google_containers/pause:3.1
docker tag registry.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
docker pull registry.aliyuncs.com/google_containers/kube-apiserver-amd64:v1.17.0
docker tag registry.aliyuncs.com/google_containers/kube-apiserver-amd64:v1.17.0 k8s.gcr.io/kube-apiserver:v1.17.0
docker pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.17.0
docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.17.0 k8s.gcr.io/kube-scheduler:v1.17.0
docker pull registry.aliyuncs.com/google_containers/kube-controller-manager:v1.17.0
docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.17.0 k8s.gcr.io/kube-controller-manager:v1.17.0
docker pull registry.aliyuncs.com/google_containers/coredns:1.6.5
docker tag registry.aliyuncs.com/google_containers/coredns:1.6.5 k8s.gcr.io/coredns:1.6.5
docker pull registry.aliyuncs.com/google_containers/etcd:3.4.3-0
docker tag registry.aliyuncs.com/google_containers/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker pull quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64
docker tag quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64 quay.io/coreos/flannel:v0.11.0-amd64
Kubeadm 常用命令
https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-config/
kubeadm config images list
// 初始化k8s
kubeadm init --apiserver-advertise-address=172.16.203.100 --pod-network-cidr 10.244.0.0/16 --ignore-preflight-errors all --node-name k8s-master
安装pod网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
记录这个,因为这个是加入集群的令牌
kubeadm join 172.16.203.100:6443 --token m074vp.re0ahabqfbttzxv4 --discovery-token-ca-cert-hash sha256:d89f464796d5fedf950ea734802be373d9e04144151cefcceaae8f432ab2b2a2 --node-name k8s-node1
重启相关服务
systemctl restart kube-apiserver
systemctl restart kube-controller-manager
systemctl restart kube-scheduler
systemctl start kube-apiserver.service
systemctl start kube-controller-manager
systemctl start kube-scheduler
kubeadm reset
rm -rf $HOME/.kube
常用命令
kubectl get nodes -n kube-system
kubectl get pods -n kube-system
kubectl describe pod kube-proxy-6xq4r -n kube-system
kubectl delete pods kube-flannel-ds-amd64-gk2vn -n kube-system
// 重启
kubectl get pod PODNAME -n NAMESPACE -o yaml | kubectl replace --force -f -
kubectl get pod kube-apiserver-localhost.localdomain -n kube-system -o yaml | kubectl replace --force -f -
Kubectl create deployment nginx —image=nginx
暴露端口
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pods,svc
kubectl get pods,svc -o wide
如果
docker pull quay.io/coreos/flannel:v0.11.0-amd64 慢可用 :docker pull quay-mirror.qiniu.com/coreos/flannel:v0.11.0-amd64
基本master 结束
(管理界面ui)
https://raw.githubusercontent.com/kubernetes/dashboard/v1.1.0.1/src/deploy/recommended.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml