k8s cookbook读书笔记 第二章
走一遍概念[*]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
/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.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: my-first-nginx
spec:
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: my-first-nginx
image: nginx
Then specify thecreate -f option to execute thekubectl command as follows
# kubectl create -f nginx.yaml
replicationcontroller "my-first-nginx" created
status of the replication controller
# kubectl get replicationcontrollers
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
my-first-nginx my-first-nginx nginx app=nginx 1 12s
缩写
kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS AGE
my
-first-nginx my-first-nginx nginx app=nginx 1 1m
删除
# kubectl delete rc my-first-nginx
replicationcontroller "my-first-nginx" deleted
2.pods
是k8s中最小的可部署单元
每个pod被进程id,网络,进程间通信,时间命名空间隔离。
docker pull centos
# cat my-first-pod.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-first-pod
spec:
containers:
- name: my-nginx
image: nginx
- name: my-centos
image: centos
command: ["/bin/sh", "-c", "while : ;do curl http://
localhost:80/; sleep 3; done"]
页:
[1]