设为首页 收藏本站
查看: 474|回复: 0

[经验分享] Kubernetes Running Locally

[复制链接]

尚未签到

发表于 2018-1-4 16:39:54 | 显示全部楼层 |阅读模式
  1. Requirements
  1) Linux
  Not running Linux? Consider running Minikube, or on a cloud provider like Google Compute Engine.
  It recommends Ubuntu16.04.
  2) Go
  You need go in your path (see here for supported versions), please make sure it is installed and in your $PATH.
  It recommends Go1.8.3+.
  $ wget https://golang.org/dl/go1.8.3.linux-amd64.tar.gz
  $ tar -C /usr/local -xzf go1.8.3.linux-amd64.tar.gz
  PS: It's better to set environments by adding the following sections into /etc/profile like this:
export PATH=$PATH:/usr/local/go/bin   #GoRootexport PATH=$PATH:/root/go/bin          #GoPath  3) Docker
  At least Docker 1.10+. Ensure the Docker daemon is running and can be contacted (try docker ps).
  Some of the Kubernetes components need to run as root, which normally works fine with docker.
  $ apt-get install docker.io
  $ docker env
  4) etcd
  You need an etcd in your path, please make sure it is installed and in your $PATH.
  It recommends etcd3.2.6+.
  $ wget https://github.com/coreos/etcd/releases/download/v3.2.6/etcd-v3.2.6-linux-amd64.tar.gz
  $ tar -C /usr/local -xzf etcd-v3.2.6-linux-amd64.tar.gz
  5) OpenSSL
  You need OpenSSL installed. If you do not have the openssl command available, the script will print an appropriate error.
  $ apt-get install openssl
  6) CFSSL
  The CFSSL binaries (cfssl, cfssljson) must be installed and available on your $PATH.
  The easiest way to get it is something similar to the following:
  $ go get -u github.com/cloudflare/cfssl/cmd/...
  PS: This command will download and build cfssl packages into $GOPATH/bin
  2. Networking
  Kubernetes is using CNI as the networking plugin, like flannel,dhcp,loopback and so forth.
  1) Build CNI
  $ go get github.com/containernetworking/plugins/...
  PS: This command will download and build CNI packages into $GOPATH/bin
  2) Add Conf
  $ mkdir -p /etc/cni/net.d
$ cat >/etc/cni/net.d/10-mynet.conf <<EOF{"cniVersion": "0.2.0","name": "mynet","type": "bridge","bridge": "cbr0","isGateway": true,"ipMasq": false,"ipam": {"type": "host-local","subnet": "10.1.0.0/24","routes": [{ "dst": "0.0.0.0/0" }]}}EOF$ cat >/etc/cni/net.d/99-loopback.conf <<EOF{"cniVersion": "0.2.0","type": "loopback"}EOF  3. Kubernetes
  1) Download
  $ git clone https://github.com/kubernetes/kubernetes.git
  2) Build
  $ cd kubernetes
  $ make
  3) Set Env
  set environments by adding the following sections into /etc/profile like this:
export KUBECONFIG=/var/run/kubernetes/admin.kubeconfig export KUBERNETES_PROVIDER=localexport LOG_LEVEL=5export ALLOW_SECURITY_CONTEXT=trueexport ALLOW_PRIVILEGED=true  4) Run
  $ cd kubernetes
  $ hack/local-up-cluster.sh           # Build and Run
  $ hack/local-up-cluster.sh -O      # Already build and Run
  5) Test
  $ cluster/kubectl.sh get pods
  $ cluster/kubectl.sh run my-nginx --image=nginx --replicas=2 --port=80
  ## begin wait for provision to complete, you can monitor the docker pull by opening a new terminal
  $ docker images
  ## you should see it pulling the nginx image, once the above command returns it
  $ docker ps
  ## you should see your container running!
  exit
  ## end wait
  ## introspect Kubernetes!
  $ cluster/kubectl.sh get pods
  PS: The following docker images will be automatically download.
  They can be shown by command "docker images".
  Actually these containers will be run to provider the Kubernetes DNS Cluster Service.
  gcr.io/google_containers/k8s-dns-sidecar-amd64
  gcr.io/google_containers/k8s-dns-kube-dns-amd64
  gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64
  gcr.io/google_containers/pause-amd64
## create a service for nginx, which serves on port 80$ cluster/kubectl.sh expose deployment my-nginx --port=80 --name=my-nginx  4. Trouble Shooting
  1) swap



    • Error

  Running with swap on is not supported, please disable swap!



    • Solution

  *>cat /proc/swaps.
  * Turn off all swap devices and files with swapoff -a.
  * Remove any matching reference found in /etc/fstab.
  * Optional: Destroy any swap devices or files found in step 1 to prevent their reuse.
  * Due to your concerns about leaking sensitive information, you may wish to consider performing some sort of secure wipe.
  2) Improvement
  $ vi s.sh
  ~/go/src/kubernetes/hack/local-up-cluster.sh -O
  $ source s.sh      # simply to run kubernetes server
  $ cp kubernetes/_output/bin/kubelet /usr/local/bin/
  $ kubelet           # simply to replace cluster/kubectl.sh into kubelet
  3) Improvement
  # export SERVICE_ACCOUNT_LOOKUP=false
# export HOSTNAME_OVERRIDE=SZX1000341409  # export NET_PLUGIN=kubenet      #just for gce
# export KUBELET_HOST=0.0.0.0  $ kubectl exec POD_NAME -it /bin/bash
$ kubetl get all --all-namespaces=true  $ kubectl logs
$ kubectl get node -o yaml  $ kubectl cluster-info dump
$ update-rc.d ServiceName remove

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-431576-1-1.html 上篇帖子: Kubernetes-Service Account 下篇帖子: kubernetes 安装备注
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表