需要先将hostname添加到/etc/hosts
1.安装docker~
yum install -y yum-utils \
device-mapper-persistent-data \
lvm2
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-nightly
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
2.开启镜像加速,并且设置docker driver为systemd
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://npluwflg.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
3.修改内核参数,不然安装报错
vim /etc/sysctl.conf #新增
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
##然后执行
sysctl -p
4.安装minikube
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
&& chmod +x minikube
sudo mkdir -p /usr/local/bin/
sudo install minikube /usr/local/bin/
5.启动kubernetes集群
minikube start --registry-mirror=https://registry.docker-cn.com --kubernetes-version v1.17.0 --driver=none --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
等。。。。
5.安装kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
测试
[root@host-172-16-56-107 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
host-172-16-56-107 Ready master 31m v1.17.0
创建一个nginx deploy
[root@host-172-16-56-107 ~]# kubectl run deploy nginx --image=nginx
deployment.apps/deploy created
[root@host-172-16-56-107 ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
deploy 0/1 1 0 5m50s
通过nodeport暴露NGINX
[root@host-172-16-56-107 ~]# kubectl expose deployment nginx --port=80 --target-port=80
service/nginx exposed
[root@host-172-16-56-107 ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 43m
nginx ClusterIP 10.96.203.233 <none> 80/TCP 6s
访问