走一遍概念
- An overview of Kubernetes control
- f Working with pods
- f Working with a replication controller
- f Working with services
- f Working with volumes
- f Working with secrets
- f Working with names
- f Working with namespaces
- f Working with labels and selectors
- An overview of Kubernetes control
查看k8s版本
% kubectl version
是如何做到的
kubectl通过restful api 连接kubernetes api server
如何工作的
kubectl [command] [TYPE] [NAME] [flags]
/usr/local/bin/kubectl run my-first-nginx --image=nginx
However, you can write either a YAML file or a JSON file to perform similar operations.
# cat nginx.yamlapiVersion: v1kind: ReplicationControllermetadata:name: my-first-nginxspec:replicas: 1template:metadata:labels:app: nginxspec:containers:- name: my-first-nginximage: nginx
Then specify the create -f option to execute the kubectl command as follows
# kubectl create -f nginx.yamlreplicationcontroller "my-first-nginx" created
status of the replication controller
# kubectl get replicationcontrollersCONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGEmy-first-nginx my-first-nginx nginx app=nginx 1 12s
缩写
kubectl get rcCONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGEmy-first-nginx my-first-nginx nginx app=nginx 1 1m
删除
# kubectl delete rc my-first-nginxreplicationcontroller "my-first-nginx" deleted
2.pods
是k8s中最小的可部署单元
每个pod被进程id,网络,进程间通信,时间命名空间隔离。
docker pull centos
# cat my-first-pod.yamlapiVersion: v1kind: Podmetadata:name: my-first-podspec:containers:- name: my-nginximage: nginx- name: my-centosimage: centoscommand: ["/bin/sh", "-c", "while : ;do curl http://localhost:80/; sleep 3; done"]