k8s

mac平台

安装brew

。。。

安装

1
brew install kubectl
1
brew cask install minikube
1
2
$ which minikube
$ minikube start

错误提示

1
stderr: failed to pull image "k8s.gcr.io/kube-apiserver:v1.13.4": output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

打印日志

1
minikube logs

使用代理:

1
2
$ minikube delete
$ minikube start --docker-env HTTP_PROXY=http://10.0.2.2:1087 --docker-env HTTPS_PROXY=http://10.0.2.2:1087

代理参考资料

https://github.com/kubernetes/minikube/blob/master/docs/http_proxy.md
https://my.oschina.net/csq/blog/3014879

配置pod

client-pod.yaml

1
2
3
4
5
6
7
8
9
10
11
12
apiVersion: v1
kind: Pod
metadata:
name: client-pod
labels:
component: web
spec:
containers:
- name: client
image: stephengrider/multi-worker
ports:
- containerPort: 3000

配置server

1
2
3
4
5
6
7
8
9
10
11
12
apiVersion: v1
kind: Service
metadata:
name: client-node-port
spec:
type: NodePort
ports:
- port: 3050
targetPort: 3000
nodePort: 31515
selector:
component: web
1
2
3
4
$ kubectl apply -f client-pod.yaml
$ kubectl apply -f client-node-port.yaml
$ kubectl get pods
$ kubectl get services

修改client-pod.yaml中的images,重新执行配置文件即可更新

1
$ kubectl apply -f client-pod.yaml

获取ip

1
$ minikube ip

获取pod详细描述

1
$ kubectl describe pod client-pod

删除pod

1
$ kubectl delete -f client-pod.yaml

书写deployment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-deployment
spec:
replicas: 1
selector:
matchLabels:
component: web
template:
metadata:
labels:
component: web
spec:
containers:
- name: client
image: stephengrider/multi-client
ports:
- containerPort: 3000
```

## 应用deployment

$ kubectl apply -f client-deployment.yaml
$ kubectl get pods
$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
client-deployment 1 1 1 1 30s

1
2

如果image有更新,可以采取下面的方式强制更新:

docker build -t stephengrider/multi-client:v5 .
docker push stephengrider/multi-client:v5
$ kubectl set image deployment/client-deployment client=stephengrider/multi-client:v5


## docker ps 得到k8s虚拟机的信息