KUBELET_HOSTNAME="--hostname-override=192.168.56.102"
KUBELET_API_SERVER="--api-servers=http://192.168.56.101:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
启动kube-proxy,kubelet,docker,flanneld服务,并且配置开机启动服务 。
# for SERVICES in kube-proxy kubelet docker flanneld;do systemctl restart $SERVICES; done
# for SERVICES in kube-proxy kubelet docker flanneld;do systemctl enable $SERVICES; done
到此,master和node节点全部配置完毕,在master上执行:
# kubectl get nodes
NAME STATUS AGE
192.168.56.102 Ready 21d
192.168.56.103 Ready 20d
# kubectl get cs
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {"health":"true"}
# kubectl get namespace
NAME STATUS AGE
default Active 21d
kube-system Active 21d
# kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2"}
# kubectl api-versions
Apps/v1beta1
authentication.k8s.io/v1beta1
authorization.k8s.io/v1beta1
autoscaling/v1
batch/v1
certificates.k8s.io/v1alpha1
extensions/v1beta1
policy/v1beta1
rbac.authorization.k8s.io/v1alpha1
storage.k8s.io/v1beta1
v1
第二种安装k8s的方法:使用docker镜像安装,k8s的基础软件在docker容器中运行 。支持最新的1.18.6的版本 。
k8s集群IP地址
主机名字 Host-Only地址 Internal Network地址
k8smaster 192.168.56.110 10.0.20.110
k8snode1 192.168.56.111 10.0.20.111
步骤一:添加主机名字# hostnamectl set-hostname master-node
# cat <<EOF>> /etc/hosts
10.0.20.110 k8smaster
10.0.20.111 k8snode1
EOF
步骤二:设置selinux和防火墙# setenforce 0
# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinu
# modprobe br_netfilter
# echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
# systemctl disable firewalld
# swapoff -a
# reboot
步骤三:设置k8s repo来源# 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
EOF
步骤四:安装docker和kube软件# yum install kubeadm docker -y
注意docker需用使用docker-ce版本
# systemctl enable kubelet
# systemctl start kubelet
# systemctl enable docker
# systemctl start docker
步骤五:下载docker镜像(master和node节点都要安装)由于国内访问k8s.gcr.io的地址非常慢,所以需要手动下载docker的image,具体什么版本1.需要跟k8s的版本一致;2.需用从https://hub.docker.com/u/library查询 。笔者整理好下面的命令:
# docker pull kubesphere/kube-apiserver:v1.18.6
# docker pull kubesphere/kube-controller-manager:v1.18.6
# docker pull kubesphere/kube-scheduler:v1.18.6
# docker pull kubesphere/kube-proxy:v1.18.6
# docker pull kubesphere/pause:3.2
# docker pull kubesphere/flannel:v0.12.0
# docker pull coreDNS/coredns:1.6.7
# docker pull azhu/etcd:3.4.3-0
下载完毕之后需要修改image的tag,让k8s认为本地的tag就是他需要安装的版本:
# docker tag docker.io/kubesphere/kube-proxy:v1.18.6 k8s.gcr.io/kube-proxy:v1.18.6
# docker tag docker.io/kubesphere/kube-apiserver:v1.18.6 k8s.gcr.io/kube-apiserver:v1.18.6
# docker tag docker.io/kubesphere/kube-controller-manager:v1.18.6 k8s.gcr.io/kube-controller-manager:v1.18.6
# docker tag docker.io/kubesphere/kube-scheduler:v1.18.6 k8s.gcr.io/kube-scheduler:v1.18.6
# docker tag docker.io/kubesphere/pause:3.2 k8s.gcr.io/pause:3.2
# docker tag docker.io/kubesphere/flannel:v0.12.0 k8s.gcr.io/flannel:v0.12.0
# docker tag docker.io/coredns/coredns:1.6.7 k8s.gcr.io/coredns:1.6.7
# docker tag docker.io/azhu/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
步骤六:初始化kube# kubeadm init --control-plane-endpoint=10.0.20.110 --apiserver-advertise-address=10.0.20.110
这里需要指定Internal Network IP地址,否则会使用默认的NAT的地址 。
当初始化完成之后,会得到下面的信息:
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
推荐阅读
- VirtualBox安装CentOS虚拟机实验
- ansible部署k8s
- 「PHP编程」安装开发环境太烦?告诉你几个简单方法,分分钟搞定
- CentOS7 定制ISO镜像
- 会声会影2020如何安装MOV解码器
- K8S常用命令
- 电脑小白怎么重装系统win10
- Oracle手动安装和卸载,这是最全的一篇了
- 蚂蚁集团针对 K8s 中 Secret 安全防护的实践与探索
- K8S部署指导书