kubernetes 初次安装使用

kubernetes 安装 yum install etcd kubernetes vim /etc/sysconfig/docker # OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false' OPTIONS='--selinux-enabled=false --insecure-registry gcr.io --log-driver=journald --signature-verification=false' vim /etc/kubernetes/apiserver # KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota" KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota" vim /etc/kubernetes/apiserver # KUBE_API_ADDRESS="--insecure-bind-address=127.0.0.1" KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" 这个后边api访问要用 一起改了 systemctl start etcd systemctl start docker systemctl start kube-apiserver systemctl start kube-controller-manager systemctl start kube-scheduler systemctl start kubelet systemctl start kube-proxy 搞一个可以执行python的镜像 docker search python docker pull docker.io/python docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/python latest b6cc5d70bc28 3 weeks ago 688.9 MB 测试 docker run -t -i b6cc5d70bc28 /bin/bash 启动输入python, 麻痹 3.6.1的,还好有python2。2.7.9 哈哈 创建个新的镜像,新建Dockerfile # 测试用滴 FROM docker.io/python EXPOSE 8080 # COPY main.py . CMD python2 -m SimpleHTTPServer 8080 docker build -t mytest/pyhttp:v1 . docker images REPOSITORY TAG IMAGE ID CREATED SIZE mytest/pyhttp v1 eefd8b0e5723 About a minute ago 688.9 MB docker.io/python latest b6cc5d70bc28 3 weeks ago 688.9 MB docker run -d eefd8b0e57 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 02e9d5c001c9 eefd8b0e57 "/bin/sh -c 'python2 " 8 seconds ago Up 6 seconds 8080/tcp jovial_shockley docker exec -i -t 02e9d5c001c9 /bin/bash ss -at State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 5 *:http-alt *:* 或者curl 127.0.0.1:8080 没问题了 docker kill 02e9d5c001c9 下边就开始搞k8s了 编辑pyhttp.yaml apiVersion: v1 kind: ReplicationController metadata: name: pyhttp spec: replicas: 2 selector: app: pyhttp template: metadata: labels: app: pyhttp spec: containers: - name: pyhttp image: mytest/pyhttp:v1 ports: - containerPort: 8080 kubectl create -f ./pyhttp.yaml replicationcontroller "pyhttp" created kubectl get rc kubectl get pods NAME READY STATUS RESTARTS AGE pyhttp-26pd2 0/1 ContainerCreating 0 1m pyhttp-v7qk2 0/1 ContainerCreating 0 1m kubectl describe replicationcontrollers/pyhttp kubectl get events 几个看状态的命令,等到都running了,就成功了 docker ps命令看启动了四个容器,两个pyhttp的。两个registry.access.redhat.com/rhel7/pod-infrastructure:latest 再写个httpserver.yaml apiVersion: v1 kind: Service metadata: name: http-service spec: type: NodePort selector: app: pyhttp ports: - protocol: TCP port: 8080 nodePort: 30080 kubectl create -f ./httpserver.yaml kubectl create -f ./httpserver.yaml service "http-service" created [root@localhost code]# kubectl get services NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE http-service 10.254.245.101 8080:30080/TCP 12s kubernetes 10.254.0.1 443/TCP 1h 然后就能通过30080访问了. 不过默认安装防火墙给过滤掉了,从机器外是访问不了的 装了个Dashboard,安装方法从官网github上装的。 我装的k8s是1.5的,安装命令 kubectl create -f https://git.io/kube-dashboard-no-rbac 默认监听的127.0.0.1需要制定地址 kubectl proxy --address='0.0.0.0' 然后就可以了 访问发现是

Unauthorized

看文档好像master上的只能在设置用户名密码的时候才能用 kubectl proxy --address='0.0.0.0' --accept-hosts='^*$' 然后跳转变成503. status: "Failure", message: "no endpoints available for service "kubernetes-dashboard"", reason: "ServiceUnavailable", 发现后端启动不成功 [root@localhost ~]# kubectl get pods --namespace=kube-system NAME READY STATUS RESTARTS AGE kubernetes-dashboard-3585514280-q29ml 0/1 CrashLoopBackOff 2 43s [root@localhost ~]# kubectl logs kubernetes-dashboard-3585514280-q29ml -n kube-system Using HTTP port: 8443 Error while initializing connection to Kubernetes apiserver. This most likely means that the cluster is misconfigured (e.g., it has invalid apiserver certificates or service accounts configuration) or the --apiserver-host param points to a server that does not exist. Reason: open /var/run/secrets/kubernetes.io/serviceaccount/token: no such file or directory Refer to the troubleshooting guide for more information: https://github.com/kubernetes/dashboard/blob/master/docs/user-guide/troubleshooting.md 然后搜索有人说要把yaml指定,发现里边确实有注释,默认不行就指定。 - --apiserver-host=http://10.254.0.1:80 这个apiserver ip 命令 kubectl describe svc kubernetes 获取 然后发现还是不行,会出现timeout,这次能running了但是一会儿还是503 但是配置成http://192.168.49.111:8080的api访问地址就行了,外网也能访问了。具体还不太了解原理

上一篇:
下一篇:

相关文章:

Categories: 博客记录

0 Responses so far.

Leave a Reply