k8s-master 初始化
- 配置 yum 源
[kubernetes]
name=kubernetes repo
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
- yum 安装
yum install -y kubelet-1.14.0 kubeadm-1.14.0 kubectl-1.14.0 --disableexcludes=kubernetes
- 配置 kubeadm init yaml文件
kubeadm config print init-defaults > init.default.yaml
# 修改镜像地址
kubeadm config images pull --config=init.default.yaml
- 完整配置文件
apiVersion: kubeadm.k8s.io/v1beta1
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
# 配置本机地址
advertiseAddress: 192.168.0.225
bindPort: 6443
nodeRegistration:
criSocket: /var/run/dockershim.sock
# 节点名称
name: k8s-master
taints:
- effect: NoSchedule
key: node-role.kubernetes.io/master
---
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta1
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: ""
controllerManager: {}
dns:
type: CoreDNS
etcd:
local:
dataDir: /var/lib/etcd
#imageRepository: k8s.gcr.io
# 配置自定义镜像库
imageRepository: registry.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: v1.14.0
networking:
dnsDomain: cluster.local
# 配置 ip 池
podSubnet: "192.168.0.0/16"
serviceSubnet: 10.96.0.0/12
scheduler: {}
报错
ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables
echo "1" >/proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables
其他命令
systemctl stop kubelet
docker stop $(docker ps -q)
docker rm $(docker ps -aq)
kubeadm reset
查看ConfigMap
[root@k8s-master k8s]# kubectl get -n kube-system configmap
NAME DATA AGE
coredns 1 13m
extension-apiserver-authentication 6 13m
kube-proxy 2 13m
kubeadm-config 2 13m
kubelet-config-1.14 1 13m
[root@k8s-master k8s]#
k8s-node 初始化
配置源
yum 安装
yum install kubelet-1.14.0 kubeadm-1.14.0 --disableexcludes=kubernetes
- 修改内核参数
cat /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
- 关闭 swap
swapoff -a
- 初始化配置文件
# token 生成, master 上执行
kubeadm token create --print-join-command
[root@tyler k8s]# cat join-config.yaml
apiVersion: kubeadm.k8s.io/v1beta1
kind: JoinConfiguration
discovery:
bootstrapToken:
apiServerEndpoint: 192.168.0.225:6443
token: dwsn99.lhlejgnyrn4pj11g
unsafeSkipCAVerification: true
tlsBootstrapToken: dwsn99.lhlejgnyrn4pj11g
- 初始化
kubeadm join --config=join-config.yaml