Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
「httpd on Karbon」とコンテナのホスト名が表示される httpd Pod を起動する。
---
kind: Service
apiVersion: v1
metadata:
name: httpd-svc
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
selector:
app: httpd
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: httpd
spec:
replicas: 1
selector:
matchLabels:
app: httpd
template:
metadata:
labels:
app: httpd
spec:
containers:
- name: httpd
image: gowatana/centos7:httpd
ports:
- containerPort: 80
protocol: TCP
command:
- bash
- -c
- |
N=$(uname -n); echo '<h1>httpd on Karbon</h1>' $N > /var/www/html/index.html; httpd -D FOREGROUND
@gowatana

This comment has been minimized.

Copy link
Owner Author

@gowatana gowatana commented Nov 22, 2020

Deployment と Service 作成

$ kubectl apply -f https://gist.githubusercontent.com/gowatana/3b065d9d800d2b65b82e339bcae5310a/raw/httpd-nodeport.yml

アドレスとポート番号を取得

$ IP=$(kubectl get endpoints  kubernetes -o jsonpath='{.subsets[0].addresses[0].ip}')
$ PORT=$(kubectl get service httpd-svc -o jsonpath='{.spec.ports[0].nodePort}')

接続確認

$ echo http://$IP:$PORT
$ curl http://$IP:$PORT
<h1>httpd on Karbon</h1> httpd-5db7885456-kl8fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment