码迷,mamicode.com
首页 > Web开发 > 详细

kubernetes installing and using

时间:2019-06-22 12:12:31      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:emctl   span   user   ogr   doc   speed   orm   tag   htm   

centos安装docker

uname -r 

yum remove docker                   docker-client                   docker-client-latest                   docker-common                   docker-latest                   docker-latest-logrotate                   docker-logrotate                   docker-selinux                   docker-engine-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缓存
yum makecache fast

安装新版docker
yum -y install docker-ce

启动测试docker
systemctl start docker
systemctl enable docker.service
docker run hello-world

添加镜像源
touch /etc/docker/daemon.json

#建议使用阿里云镜像源
http://hub-mirror.c.163.com
https://2lqq34jg.mirror.aliyuncs.com# 

  删除docker
  yum remove docker-ce
  rm -rf /var/lib/docker

 

 

安装阿里云的k8s-yum源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
EOF

安装kubelet

setenforce 0
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet

调参运行(网桥)

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

systemctl daemon-reload
systemctl restart kubelet

本机kubernetes-version=v1.15.0

命令:kubeadm config images list
显示如下:
k8s.gcr.io/kube-apiserver:v1.15.0
k8s.gcr.io/kube-controller-manager:v1.15.0
k8s.gcr.io/kube-scheduler:v1.15.0
k8s.gcr.io/kube-proxy:v1.15.0
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1

拉去阿里云镜像替换k8s谷歌镜像

cat ./pull.sh
for i in `kubeadm config images list`; do 
  imageName=${i#k8s.gcr.io/}
  docker pull registry.aliyuncs.com/google_containers/$imageName
  docker tag registry.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
  docker rmi registry.aliyuncs.com/google_containers/$imageName
done;

安装单节点k8s

禁用交换分区:/sbin/swapoff -a

kubeadm init --kubernetes-version=v1.15.0 --pod-network-cidr=10.244.0.0/16 [init] Using Kubernetes version: v1.15.0 [preflight] Running pre-flight checks [preflight] Pulling images required for setting up a Kubernetes cluster [preflight] This might take a minute or two, depending on the speed of your internet connection [preflight] You can also perform this action in beforehand using kubeadm config images pull [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Activating the kubelet service [certs] Using certificateDir folder "/etc/kubernetes/pki"

安装网络组件(flannel)

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

取消污点(因为是单机部署,需要剔除本机节点,k8s才可以运行)

kubectl taint nodes --all node-role.kubernetes.io/master-

安装k8s dashboard视图

#Create a new ServiceAccount
kubectl create serviceaccount k8sadmin -n kube-system

#Create a ClusterRoleBinding with Cluster Admin Privileges
kubectl create clusterrolebinding k8sadmin --clusterrole=cluster-admin --serviceaccount=kube-system:k8sadmin

#Get the token 生成视图token
kubectl get secret -n kube-system | grep k8sadmin | cut -d " " -f1 | xargs -n 1 | xargs kubectl get secret  -o jsonpath={.data.token} -n kube-system | base64 --decode

执行以上命令,最后一条命令或获取到一串token,直接使用得到的token登录dashboard。

# 安装dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

安装WeaveScope

kubectl apply -f "https://cloud.weave.works/k8s/scope.yaml?k8s-version=$(kubectl version | base64 | tr -d ‘\n‘)"

# 设置端口映射
kubectl port-forward --address=0.0.0.0 -n weave "$(kubectl get -n weave pod --selector=weave-scope-component=app -o jsonpath=‘{.items..metadata.name}‘)" 4040

浏览器访问该节点,http://{IP}:4040

技术图片

 

参考来源

 

kubernetes installing and using

标签:emctl   span   user   ogr   doc   speed   orm   tag   htm   

原文地址:https://www.cnblogs.com/ipyanthony/p/11068355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!