Home > Archives > k8s 1

k8s 1

Publish:

[root@localhost ~]# which minikube
[root@localhost ~]# which kubectl

[root@localhost ~]# minikube status

[root@localhost ~]# docker version
[root@localhost ~]# docker container list
[root@localhost ~]# docker ps
[root@localhost ~]# docker pull googlecontainer/echoserver:1.8

[root@localhost ~]# kubectl get deployments
[root@localhost ~]# kubectl get pods
[root@localhost ~]# kubectl delete deployment sa-frontend
[root@localhost ~]# kubectl run hello-minikube --image=googlecontainer/echoserver:1.8 --port=8080
[root@localhost ~]# kubectl expose deployment hello-minikube --type=NodePort
[root@localhost ~]# minikube service hello-minikube --url
http://127.0.0.1:30520
[root@localhost ~]# kubectl get pods --watch
[root@localhost ~]# kubectl get svc
[root@localhost ~]# kubectl delete svc sa-web-app-lb


# HELLO-MINIKUBE

[root@localhost ~]# docker pull googlecontainer/echoserver:1.8
[root@localhost ~]# kubectl run hello-minikube --image=googlecontainer/echoserver:1.8 --port=8080
[root@localhost ~]# kubectl expose deployment hello-minikube --type=NodePort
[root@localhost ~]# minikube service hello-minikube --url
http://127.0.0.1:30520



# DOCKER CONTAINERS

[root@localhost docker-demo]# docker build .
[root@localhost docker-demo]# docker image list
[root@localhost docker-demo]# docker run -p 3000:3000 -it db12bf098771


# FROM DOCKER IMAGE TO DOCKER HUB

[root@localhost ~]# docker image ls
[root@localhost ~]# docker tag db12bf098771 baoguoding/docker-demo
[root@localhost ~]# docker tag db12bf098771 baoguoding/docker-demo:v1.0.0
[root@localhost ~]# docker rmi -f baoguoding/docker-demo:v1.0.0
[root@localhost ~]# docker push baoguoding/docker-demo

# CREATE POD

[root@localhost ~]# minikube stop
[root@localhost ~]# service docker stop
[root@localhost ~]# rm -rf /var/lib/docker
[root@localhost ~]# rm -rf ~/.kube
[root@localhost ~]# kubeadm reset
[root@localhost ~]# service docker start
[root@localhost ~]# minikube start --vm-driver=none --bootstrapper=localkube

[root@localhost ~]# vim /etc/docker/daemon.json

{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}


[root@localhost ~]# vim /lib/systemd/system/docker.service

BEFORE:
ExecStart=/usr/bin/dockerd

AFTER:
ExecStart=/usr/bin/dockerd -g /home/baoguoding/docker
ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT

iptables -P FORWARD ACCEPT //只是放这边,没有用

[root@localhost ~]# systemctl stop docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker system df
[root@localhost ~]# docker info
[root@localhost ~]# docker images ls
[root@localhost ~]# docker container ls
[root@localhost ~]# docker version

[root@localhost ~]# docker run hello-world


[root@localhost demo-pod]# kubectl create -f my-first-pod.yaml
[root@localhost demo-pod]# kubectl get pods --show-all
[root@localhost demo-pod]# kubectl describe pods my-pod
[root@localhost demo-pod]# kubectl port-forward my-pod 8000:3000
[root@localhost demo-pod]# kubectl expose pod my-pod --type=NodePort --name=my-pod-service
[root@localhost demo-pod]# kubectl get services
[root@localhost demo-pod]# minikube service my-pod-service --url
http://127.0.0.1:30374
[root@localhost demo-pod]# kubectl attach my-pod -i
[root@localhost demo-pod]# kubectl exec my-pod -- ls /app
[root@localhost demo-pod]# kubectl get pod --show-labels
[root@localhost demo-pod]# kubectl run -i --tty alpine --image=alpine --restart=Never -- sh


[root@localhost demo-pod]# journalctl -f -u kubelet

参考

kubernetes 简介:kubelet 和 pod

纯手工搭建k8s集群-预先准备环境

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo