Skip to content

Instantly share code, notes, and snippets.

@zhangyuan
Last active May 2, 2018 13:18
Show Gist options
  • Save zhangyuan/85b42a7649edc42a9dfc968c3944e85e to your computer and use it in GitHub Desktop.
Save zhangyuan/85b42a7649edc42a9dfc968c3944e85e to your computer and use it in GitHub Desktop.
// npm i @kubernetes/client-node
const Extensions_v1beta1Api = require('@kubernetes/client-node/dist/api').Extensions_v1beta1Api;
const ENDPOINT = 'https://x.x.x.x'; // (IP CAN BE FOUND FROM RESPONSE OF GKE getCluster API)
const USERNAME = 'admin'; // (THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API)
const PASSWORD = ''; // THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API
const BASE64_ENCODED_CA = ''; // THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API
const BASE64_ENCODED_CERT = ''; // THIS CAN BE FOUND FROM RESPONSE OF GKE getCluster API
function nginxDeployment() {
return {
metadata: {
name: 'nginx-deployment',
labels: {
app: 'nginx'
}
},
spec: {
replicas: 2,
selector: {
matchLabels: {
app: 'nginx'
}
},
template: {
metadata: {
labels: {
app: 'nginx'
}
},
spec: {
containers: [
{
name: 'nginx',
image: 'nginx:1.7.9',
ports: [
{
containerPort: 80
}
]
}
]
}
}
}
};
}
(async () => {
// since the underneath http client is request, check https://github.com/request/request#tlsssl-protocol for more information.
const authentication = {
'applyToRequest': (opts) => {
opts.auth = {
username: USERNAME, password: PASSWORD
};
opts.ca = Buffer.from(BASE64_ENCODED_CA, 'base64');
opts.key = Buffer.from(BASE64_ENCODED_CERT, 'base64');
}
};
const extensionsV1beta1Api = new Extensions_v1beta1Api(ENDPOINT)
extensionsV1beta1Api.setDefaultAuthentication(authentication);
const createDeploymentRes = await extensionsV1beta1Api.createNamespacedDeployment('default', nginxDeployment())
console.log(createDeploymentRes.response.body);
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment