kubernetes installing and using
Posted ipyanthony
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kubernetes installing and using相关的知识,希望对你有一定的参考价值。
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
参考来源
http://ljchen.net/2018/10/23/%E5%9F%BA%E4%BA%8E%E9%98%BF%E9%87%8C%E4%BA%91%E9%95%9C%E5%83%8F%E7%AB%99%E5%AE%89%E8%A3%85kubernetes/
https://opsx.alibaba.com/mirror?lang=zh-CN
https://www.runoob.com/docker/centos-docker-install.html
以上是关于kubernetes installing and using的主要内容,如果未能解决你的问题,请参考以下文章
How to install Kubernetes with Kubeadm
Microsoft launches Open Application Model (OAM) and Dapr to ease developments in Kubernetes and micr
大咖云集!Kubernetes and Cloud Native Meetup 广州站开放报名!