K8s 安装
K8s 安装部署
可以参考链接
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
#所有节点操作
ntpdate time1.aliyun.com
date
crontab -e
systemctl disable firewalld
systemctl stop firewalld
setenforce 0
vim /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
swapoff -a
vim /etc/fstab
yum remove docker docker-common docker-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum -y --setopt=obsoletes=0 install docker-ce-17.03.0.ce-1.el7.centos
systemctl enable docker && systemctl start docker
docker version
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=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum search kubeadm
yum install -y kubelet kubeadm kubectl kubernetes-cni
systemctl enable kubelet && systemctl start kubelet
vim image2.sh
images=(
kube-apiserver:v1.14.0
kube-controller-manager:v1.14.0
kube-scheduler:v1.14.0
kube-proxy:v1.14.0
pause:3.1
etcd:3.3.10
coredns:1.3.1
kubernetes-dashboard-amd64:v1.10.1
heapster-grafana-amd64:v5.0.4
heapster-influxdb-amd64:v1.5.2
heapster-amd64:v1.5.4
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName} k8s.gcr.io/${imageName}
#docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
done
sh image2.sh
docker image ls
kubeadm config images list
#master初始化
kubeadm init --kubernetes-version=v1.14.0 --pod-network-cidr=10.244.0.0/16
##根据回显操作
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
#kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.11.0/Documentation/kube-flannel.yml
#查看pods
kubectl get pods --all-namespaces
#slave加入节点
kubeadm join 192.168.115.146:6443 --token f8pwe2.13tqwhy020mn580a \
--discovery-token-ca-cert-hash sha256:69056be6342088ce82d8409f2df96765d1e1f9f84e31e2cd85c966efe472e540
#重置节点
kubeadm reset
#从节点网络问题
kubeadm reset
systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker
---------------------
#无法加入节点有可能是
1、时间不同步
2、3台服务器的主机名相同
#安装dashboard
#wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
添加在service出
type: NodePort
kubectl create -f kubernetes-dashboard.yaml
vim kubernetes-dashboard-admin.rbac.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-admin
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard-admin
labels:
k8s-app: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard-admin
namespace: kube-system
kubectl create -f kubernetes-dashboard-admin.rbac.yaml
kubectl -n kube-system get secret | grep kubernetes-dashboard-admin
kubectl describe -n kube-system secret/kubernetes-dashboard-admin-token-464mz
eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbi10b2tlbi05NXR3cyIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6Ijk3NTIyY2FmLTU0NjMtMTFlOS04YzU3LTAwMGMyOTg5MjhlYiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTprdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiJ9.iLCOCYRg3dHV9rpkHunXm2Xhkt7aYYtv8OeA-cy-b2VPiIhejpZYDrsrTmA-DYfuc7Foq7339e_e2yvkZv_aAQTrQjXzMP4ooHkDoTnArPAxm0kpHHUTzWXJEPCS8inxuawuoqmauLDqV-g7gz7gtz-kYfWJuuNKBjKKO-NL_0N4-GEv9T_NP2KMLdKcqh0QIr0HVvN-Mt4Qw4aupYKLn7bD_NRhbHcTqPTfzzxpnqTK6deKyJ_5Ib1DXftvA9D87Zu38Ll2GsmQUDQU7QFuwozbsp6XbTKfifyq_YpjkVPotUoxZYxN8bQW4MfWQ1utgvTHEfmXqUYHEq5PqmnT4Q
kubectl get svc -n kube-system
mkdir -p ~/k8s/heapster
cd ~/k8s/heapster
wget https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/influxdb/grafana.yaml
wget https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/rbac/heapster-rbac.yaml
wget https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/influxdb/heapster.yaml
wget https://raw.githubusercontent.com/kubernetes/heapster/master/deploy/kube-config/influxdb/influxdb.yaml
kubectl create -f ./
###############常见命令
#查看详情
kubectl get pods -o wide -n kube-system
#显示node详情(查看报错信息)
kubectl describe node k8s-node1
kubectl describe pod kubernetes-dashboard-5f7b999d65-qftqb -n kube-system
命令部署应用到k8s中
先创建pods
kubectl run xclarity-web --image=10.121.223.50/library/web:201965 --port=80
创建services
kubectl expose deployment/xclarity-web --type="NodePort" --port 80
扩容副本集
kubectl scale deployments/xclarity-web --replicas=2
本文来自博客园,作者:haonan071,转载请注明原文链接:https://www.cnblogs.com/zhanghn8/p/11278275.html