编程知识 cdmana.com

K8s introduction ------ 1, k8s 1.19.2 installation

Environmental Science :

 

Host name IP operating system docker k8s edition remarks
k8s-master 10.13.19.51 Centos 7.9 19.03.13 1.19.2 master node
k8s-node01 10.13.19.52 Centos 7.9 19.03.13 1.19.2 node node
k8s-node02 10.13.19.53 Centos 7.9 19.03.13 1.19.2 node node

One 、Docker install

All nodes need to be installed docker
 

1. Install alicloud docker Source

[root@centos7 ~]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

 

2. install docker

 

2.1 docker Installation version view

[root@centos7 ~]# yum list docker-ce --showduplicates | sort -r`

2.2 install docker

[root@centos7 ~]# yum -y install docker-ce-19.03.13 bash-completion

3. Configure image Accelerator

3.1 To configure daemon.json file

[root@centos7 ~]# mkdir -p /etc/docker
[root@centos7 ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF





Restart the service

[root@centos7 ~]# systemctl daemon-reload
[root@centos7 ~]# systemctl enable --now docker

Accelerator configuration complete
 

Two 、k8s Preparation for installation  

install Centos The firewall and... Have been disabled selinux And set up alisource .master and node All nodes perform this part of the operation .

1. Configure host name

 

1.1 Modify hostname

[root@centos7 ~]# hostnamectl set-hostname k8s-master
[root@centos7 ~]# hostname
k8s-master

Log out and log in again to display the new host name k8s-master
 

1.2 modify hosts file

[root@master ~]# cat >> /etc/hosts << EOF
10.13.19.51 k8s-master
10.13.19.52 k8s-node01
10.13.19.53 k8s-node02
EOF



2. verification mac Address uuid

[root@master ~]# cat /sys/class/net/ens33/address
[root@master ~]# cat /sys/class/dmi/id/product_uuid

Ensure that each node mac and uuid only
 

3. Ban swap

 

3.1 Temporarily disabled

[root@k8s-master ~]# swapoff -a

3.2 Permanently disabled

If it needs to be restarted, it will take effect , Disabled at swap After that, you need to modify the configuration file /etc/fstab, notes swap

[root@k8s-master ~]# sed -i.bak '/swap/s/^/#/' /etc/fstab

4. Kernel parameter modification

[root@k8s-master ~]# cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
[root@k8s-master ~]# sysctl -p /etc/sysctl.d/k8s.conf



5. Set up kubernetes Source

 

5.1 newly added kubernetes Source

[root@k8s-master ~]# 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
repo_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







5.2 Update cache

[root@k8s-master ~]# yum clean all
[root@k8s-master ~]# yum -y makecache

3、 ... and 、Master Node installation

 

1. install kubelet、kubeadm and kubectl

 

1.1 Install three packages

[root@k8s-master ~]# yum install -y kubelet-1.19.2 kubeadm-1.19.2 kubectl-1.19.2

1.2 Installation package instructions

kubelet Running on all nodes of the cluster , Used to start Pod And objects such as containers
kubeadm Used to initialize the cluster , The command tool to start the cluster
kubectl Command line for communicating with the cluster , adopt kubectl Can deploy and manage applications , View resources , establish 、 Delete and update various components

 

1.3 start-up kubelet

start-up kubelet And set boot up

[root@k8s-master ~]# systemctl enable --now kubelet

1.4 kubelet Command Completion

[root@k8s-master ~]# source /usr/share/bash-completion/bash_completion
[root@k8s-master ~]# echo "source <(kubectl completion bash)" >> ~/.bash_profile
[root@k8s-master ~]# source .bash_profile

2. initialization Master

 

2.1 initialization

[root@master ~]# kubeadm init \
--apiserver-advertise-address=10.13.19.51 \
--image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \
--kubernetes-version v1.19.2 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16




apiserver-advertise-address Appoint master Of interface,pod-network-cidr Appoint Pod Scope of the network , Use here flannel Network plan .

Record kubeadm join Output , Later, you need this command to add each node to the cluster .
 

2.2 Load environment variables

[root@k8s-master ~]# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
[root@k8s-master ~]# source .bash_profile
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config



2.3. To configure hosts

cat >> /etc/hosts << EOF
151.101.108.133 raw.githubusercontent.com
EOF

2.4. install pod The Internet

[root@k8s-master ~]# wget https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml
[root@k8s-master ~]# kubectl apply -f kube-flannel.yml

Four 、Node Node installation

 

1. install kubelet、kubeadm and kubectl

 
Same as master node
 

2. Download mirroring

 
Same as master node
 

3. To join the cluster

 
The following operations master On the implementation
 

3.1 View token

[root@k8s-master ~]# kubeadm token list
TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS
j5eoyz.zu0x6su7wzh752b3 <invalid> 2019-06-04T17:40:41+08:00 authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token

Found that the token that was initialized before has expired
 

3.2 Generate a new token

[root@master ~]# kubeadm token create
1zl3he.fxgz2pvxa3qkwxln

3.3 Generate a new encrypted string

[root@master ~]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \
openssl dgst -sha256 -hex | sed 's/^.* //'

3.4 node Nodes join the cluster

 
stay node Perform the following operations on each node :

[root@node01 ~]# kubeadm join 10.13.19.51:6443 --token 1zl3he.fxgz2pvxa3qkwxln --discovery-token-ca-cert-hash sha256:5f656ae26b5e7d4641a979cbfdffeb7845cc5962bbfcd1d5435f00a25c02ea50

5、 ... and 、 Cluster testing

 

1. Deploy the application

 

1.1 Command mode

[root@master ~]# kubectl run httpd --image=httpd --replicas=3
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/httpd-app created

Deploy through the command line apache service
 

1.2 Configuration file mode

cat >> nginx.yml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
restartPolicy: Always
containers:












  • name: nginx
    image: nginx:latest
    EOF

 

[root@master ~]# kubectl apply -f nginx.yml
deployment.apps/nginx created

Deploy through configuration file nginx service
 

2. Status view

 

2.1 View node status

[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready master 1h v1.19.2
node01 Ready <none> 1h v1.19.2
node02 Ready <none> 1h v1.19.2



2.2 see pod state

[root@k8s-master ~]# kubectl get pod --all-namespaces

2.3 Check the number of copies

[root@master ~]# kubectl get deployments --all-namespaces

[root@master ~]# kubectl get pod -o wide --all-namespaces

2.4 see deployment Details

[root@master ~]# kubectl describe deployments

2.5 View the status of the cluster basic components

[root@master ~]# kubectl get cs
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health":"true"}



complete Centos7.9 Next k8s(v1.19.2) Cluster deployment .

版权声明
本文为[osc_ 2y6i16fz]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225124124209l.html

Scroll to Top