K8S学习笔记01 Centos7安装Kubeadm

安装Kubeadm

环境配置

关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

关闭selinux

# 永久
sed -i 's/enforcing/disabled/' /etc/selinux/config 

# 临时
setenforce 0

关闭 swap

# 临时
swapoff -a  

# 永久
sed -ri 's/.*swap.*/#&/' /etc/fstab

重置主机名

hostnamectl set-hostname k8smaster

配置hosts

cat >> /etc/hosts << EOF 
10.206.0.15 k8s-master 
10.206.0.17 k8s-node1 
10.206.0.10 k8s-node2 
EOF

配置网络

cat > /etc/sysctl.d/k8s.conf << EOF 
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1 
EOF

# 生效
sysctl --system 

时间同步

yum install ntpdate -y
ntpdate time.windows.com

安装Docker

安装docker

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo 

yum -y install docker-ce-18.06.1.ce-3.el7 

systemctl enable docker && systemctl start docker 

docker --version

添加阿里云YUM源

设置仓库地址:https://help.aliyun.com/docum...

cat > /etc/docker/daemon.json << EOF
{ 
  "registry-mirrors": ["https://xxx.mirror.aliyuncs.com"] 
}
EOF

添加 yum 源

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 
epo_gpgcheck=0 
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg 
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg 
EOF

安装kubelet kubeadm kubectl

yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0


systemctl enable kubelet

部署Kubenetes Master

在Master节点执行

kubeadm init --apiserver-advertise-address=10.206.0.15 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.18.0 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16

得到token

kubeadm join 10.206.0.15:6443 --token iv8baz.f2yagtk257ilmanr \
    --discovery-token-ca-cert-hash sha256:b43a11c9feeab057ee3d6ee91fd7e96dfc75859911f96ff1e89e9578d0801c23 

提示使用kubectl工具

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

kubectl get nodes

安装Node节点

执行kubeadm join

kubeadm join 10.206.0.15:6443 --token iv8baz.f2yagtk257ilmanr \
    --discovery-token-ca-cert-hash sha256:b43a11c9feeab057ee3d6ee91fd7e96dfc75859911f96ff1e89e9578d0801c23 

部署CNI网络插件

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

#手动拉取镜像
docker pull quay.io/coreos/flannel:v0.14.0

kubectl apply -f kube-flannel.yml

部署成功

kubectl get pods -n kube-system

NAME                                 READY   STATUS     RESTARTS   AGE
kube-flannel-ds-2lzv7                0/1     Init:0/1   0          3m9s
kube-flannel-ds-2qh8t                0/1     Init:0/1   0          3m9s
kube-flannel-ds-72fb7                0/1     Init:0/1   0          3m9s

节点运行成功

kubectl get nodes

NAME         STATUS   ROLES    AGE   VERSION
k8s-master   Ready    master   54m   v1.18.0
k8s-node1    Ready       44m   v1.18.0
k8s-node2    Ready       44m   v1.18.0

测试kubernetes集群

创建一个pod

kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl get pod,svc

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
service/kubernetes   ClusterIP   10.96.0.1               443/TCP        148m
service/nginx        NodePort    10.97.184.183           80:31312/TCP   4s

测试访问

curl http://公网IP:31312

K8S学习笔记01 Centos7安装Kubeadm_第1张图片

你可能感兴趣的:(K8S学习笔记01 Centos7安装Kubeadm)