1.修改配置文件
cp coredns.yaml.base coredns.yaml
diff coredns.yaml.base coredns.yaml
61c61
< kubernetes __PILLAR__DNS__DOMAIN__ in-addr.arpa ip6.arpa {
---
> kubernetes cluster.local. in-addr.arpa ip6.arpa {
153c153
< clusterIP: __PILLAR__DNS__SERVER__
---
> clusterIP: 10.254.0.2
2.创建
kubectl create -f coredns.yaml
输出
serviceaccount "coredns" created
clusterrole.rbac.authorization.k8s.io "system:coredns" created
clusterrolebinding.rbac.authorization.k8s.io "system:coredns" created
configmap "coredns" created
deployment.extensions "coredns" created
service "coredns" created
3.检查
kubectl get all -n kube-system(等2分中启动后状态为READY 为1/1)
NAME READY STATUS RESTARTS AGE
pod/coredns-77c989547b-dhvwr 1/1 Running 0 4m
pod/coredns-77c989547b-qpmsw 1/1 Running 0 4m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/coredns ClusterIP 10.254.0.2 <none> 53/UDP,53/TCP 4m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/coredns 2 2 2 2 4m
NAME DESIRED CURRENT READY AGE
replicaset.apps/coredns-77c989547b 2 2 2 4m
4.新建一个 Deployment
cat > my-nginx.yaml <<EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 2
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- name: my-nginx
image: nginx:1.7.9
ports:
- containerPort: 80
EOF
kubectl create -f my-nginx.yaml
5.Export 该 Deployment, 生成 my-nginx 服务
kubectl expose deploy my-nginx
输出
service "my-nginx" exposed
kubectl get services --all-namespaces |grep my-nginx
输出
default my-nginx ClusterIP 10.254.71.173 <none> 80/TCP 2d
6.创建另一个pod
$ cat > pod-nginx.yaml <<EOF
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- containerPort: 80
EOF
$ kubectl create -f pod-nginx.yaml
进入nginx
kubectl exec nginx -i -t -- /bin/bash