k8s部署
Posted smlile-you-me
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s部署相关的知识,希望对你有一定的参考价值。
节点 IP地址
master 192.168.1.202
node1 192.168.1.205
node2 192.168.1.206
注:所有机器的配置都一样
[[email protected] ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[[email protected] ~]# uname -r
3.10.0-693.el7.x86_64
CPU: 2C
Mem: 4G
disk: 100G
[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.202 master
192.168.1.205 node1
192.168.1.206 node2
scp /etc/hosts [email protected]:/etc/
scp /etc/hosts [email protected]:/etc/
配置ssh:
ssh-copy-id 192.168.1.205
ssh-copy-id 192.168.1.206
注:例如第一次使用 ssh node2 时会需要手动输入一次密码
安装
系统初始化安装(所有主机)--【最小化安装】
[[email protected] ~]# yum -y install epel-release
[[email protected] ~]# yum -y update
[[email protected] ~]# yum -y install etcd kubernetes-master ntp flannel
[[email protected] ~]# yum -y install kubernetes-node ntp flannel docker
[[email protected] ~]# yum -y install kubernetes-node ntp flannel docker
时间校对(所有主机上执行)
systemctl start ntpd;systemctl enable ntpd
ntpdate ntp1.aliyun.com
hwclock -w
配置etcd服务器
[[email protected] ~]# grep -v ‘^#‘ /etc/etcd/etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://192.168.1.202:2379"
ETCD_NAME="default"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.202:2379"
启动服务
systemctl start etcd;systemctl enable etcd
检查etcd cluster状态
[[email protected] ~]# etcdctl cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://192.168.1.202:2379
cluster is healthy
检查etcd集群成员列表,这里只有一台
[[email protected] ~]# etcdctl member list
8e9e05c52164694d: name=default peerURLs=http://localhost:2380 clientURLs=http://192.168.1.202:2379 isLeader=true
配置kube-apiserver配置文件
[[email protected] ~]# cat /etc/kubernetes/config|grep -v ^#|grep -v ^$
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://192.168.1.202:8080"
[[email protected] ~]# cat /etc/kubernetes/apiserver|grep -v ^#|grep -v ^$
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.1.202:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=AlwaysAdmit"
KUBE_API_ARGS=""
配置kube-controller-manager配置文件
[[email protected] ~]# cat /etc/kubernetes/controller-manager|grep -v ^#|grep -v ^$
KUBE_CONTROLLER_MANAGER_ARGS=""
配置kube-scheduler配置文件
[[email protected] ~]# cat /etc/kubernetes/scheduler|grep -v ^#|grep -v ^$
KUBE_SCHEDULER_ARGS="--address=0.0.0.0"
启动服务
[[email protected] ~]# for i in kube-apiserver kube-controller-manager kube-scheduler;do systemctl restart $i; systemctl enable $i;done
==================================================================================================
配置node1节点服务器
配置etcd
[[email protected] ~]# etcdctl set /atomic.io/network/config ‘{"Network": "172.16.0.0/16"}‘
{"Network": "172.16.0.0/16"}
配置node1网络(flannel方式来配置)
[[email protected] ~]# cat /etc/sysconfig/flanneld|grep -v ^#|grep -v ^$
FLANNEL_ETCD_ENDPOINTS="http://192.168.1.202:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
FLANNEL_OPTIONS=""
配置node1 kube-proxy
[[email protected] ~]# cat /etc/kubernetes/config|grep -v ^#|grep -v ^$
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://192.168.1.202:8080"
[[email protected] ~]# cat /etc/kubernetes/proxy|grep -v ^#|grep -v ^$
KUBE_PROXY_ARGS="--bind=address=0.0.0.0"
配置node1 kubelet
[[email protected] ~]# cat /etc/kubernetes/kubelet|grep -v ^#|grep -v ^$
KUBELET_ADDRESS="--address=127.0.0.1"
KUBELET_HOSTNAME="--hostname-override=192.168.1.205"
KUBELET_API_SERVER="--api-servers=http://192.168.1.202:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
启动node1服务
[[email protected] ~]# for i in flanneld kube-proxy kubelet docker;do systemctl restart $i;systemctl enable $i;systemctl status $i ;done
==================================================================================================
配置node2节点服务器
[[email protected] ~]# cat /etc/sysconfig/flanneld |grep -v ^#|grep -v ^$
FLANNEL_ETCD_ENDPOINTS="http://192.168.1.202:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
FLANNEL_OPTIONS=""
[[email protected] ~]# cat /etc/kubernetes/config|grep -v ^#|grep -v ^$
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://192.168.1.202:8080"
[[email protected] ~]# cat /etc/kubernetes/proxy |grep -v ^#|grep -v ^$
KUBE_PROXY_ARGS="0.0.0.0"
[[email protected] ~]# cat /etc/kubernetes/kubelet|grep -v ^#|grep -v ^$
KUBELET_ADDRESS="--address=127.0.0.1"
KUBELET_HOSTNAME="--hostname-override=192.168.1.206"
KUBELET_API_SERVER="--api-servers=http://192.168.1.202:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
启动node2服务:
for i in flanneld kube-proxy kubelet docker;do systemctl restart $i;systemctl enable $i;systemctl status $i ;done
查看节点
[[email protected] ~]# kubectl get nodes
NAME STATUS AGE
192.168.1.205 Ready 42m
192.168.1.206 Ready 22s
建立pod
[[email protected] ~]# kubectl run nginx --image=nginx --port=80 --replicas=2
[[email protected] ~]# kubectl describe pods nginx
报错:
以上是关于k8s部署的主要内容,如果未能解决你的问题,请参考以下文章